For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > April 2004 > insert CSV in mySql problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author insert CSV in mySql problem
Richard Sauve

2004-04-30, 2:32 am

Hi,

The script below add twice the same line from de CSV in the DB,
Is there something I am missing...

-------
$link = mysql_connect("localhost","","");
$selection = mysql_select_db("table", $link);
$line = array();
$fclients = fopen("file.csv","r");
while ($line = fgetcsv($fclients, 1500, ",")) {
$name_cie = addslashes(trim($line[0]));
$adress = addslashes(trim($line[1]));
$tel = addslashes(trim($line[3]));
$fax = addslashes(trim($line[4]));
$mail = addslashes(trim($line[5]));
$name = addslashes(trim($line[6]));
$title = addslashes(trim($line[7]));
$site = addslashes(trim($line[8]));
}
$request = "INSERT INTO contact
(name_cie,adress,tel,fax,mail,name,title
,site,description)";
$request .= "VALUES
('$name_cie','$adresse','$tel','$fax','$
mail','$name','$title','$site','$des
cription')";
$result = mysql_query($request) or DIE("Error: " . mysql_error()) ;
-------

Any help would be appreciated.

R. Sauve


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com