Jump to content

Help with Importing


JSHINER

Recommended Posts


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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.