JSHINER Posted March 1, 2008 Share Posted March 1, 2008 require('Database.php'); while ($row = fgetcsv($handle)) { $db->query(' INSERT INTO user (field_a, field_b) VALUES (' . $db->escape(trim($row[1])) . ', ' . $db->escape(trim($row[2])) . ') WHERE id = ' . $db->escape(trim($row[0]))); } fclose($handle); $db->close(); My CSV file looks like: 000017, 550, 550 000007, 996, 600 When I run this I get the error: Fatal error: Error in database query. Query was [ INSERT INTO user (field_a, field_b) VALUES (550, 550\r000007) WHERE id = 000017] and the error returned was [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\r000007) WHERE id = 000017' at line 2] in ... Any ideas why? Link to comment https://forums.phpfreaks.com/topic/93810-help-with-importing/ Share on other sites More sharing options...
JSHINER Posted March 1, 2008 Author Share Posted March 1, 2008 I can't post this as code for some reason won't let me ... $db = new Database(); $handle = fopen ( ' test_points.csv ' , ' r ' ); ^^^ Had to add spaces to be allowed to post. Link to comment https://forums.phpfreaks.com/topic/93810-help-with-importing/#findComment-480707 Share on other sites More sharing options...
trq Posted March 1, 2008 Share Posted March 1, 2008 Values should be surrounded by quotes in mysql. Link to comment https://forums.phpfreaks.com/topic/93810-help-with-importing/#findComment-480709 Share on other sites More sharing options...
JSHINER Posted March 1, 2008 Author Share Posted March 1, 2008 Tried that - nothing. Any other thoughts? Link to comment https://forums.phpfreaks.com/topic/93810-help-with-importing/#findComment-480946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.