jeeves245 Posted August 3, 2009 Share Posted August 3, 2009 Hi guys, can anyone tell me why this script isn't working? It is inserting the rows in the database, but they do not have any data in them. Cheers. <?php $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $file_handle = fopen("deliveries.csv", "rb"); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode(',', $line_of_text); $sql="INSERT INTO customer (customerName, address1, address2, address3) VALUES ('$parts[2]','$parts[6]','$parts[7]','$parts[8]')"; } fclose($file_handle); if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } ?> Link to comment https://forums.phpfreaks.com/topic/168576-solved-handling-csv-file/ Share on other sites More sharing options...
abazoskib Posted August 3, 2009 Share Posted August 3, 2009 after declaring the sql statement, you must use mysql_query($sql); Link to comment https://forums.phpfreaks.com/topic/168576-solved-handling-csv-file/#findComment-889268 Share on other sites More sharing options...
jeeves245 Posted August 3, 2009 Author Share Posted August 3, 2009 Ah, that did it. Thanks Link to comment https://forums.phpfreaks.com/topic/168576-solved-handling-csv-file/#findComment-889336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.