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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
JSHINER Posted March 1, 2008 Author Share Posted March 1, 2008 Tried that - nothing. Any other thoughts? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.