I am currently trying to do quite a simple task. Information is retrieved by "post.php" where it is processed and should be inserted in a database, if the ID (auto increment) doesn't exist, or update the data if the ID exists.
Running the script writes nothing in the database. I have tried to print the query in a page, and copy/paste the SQL into PhpMyAdmin. It returns
#1064 - 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 'long, description, mobile, type, reported, embed, live, img_url) VALUES ('', 'TE' at line 1
My code is:
$query="INSERT INTO
xxy
(ID
, name
, address
, lat
, long
, description
, mobile
, type
, reported
, embed
, live
, img_url
) VALUES('$id', '$name', '$address', '$lat', '$lon', '$description', '$mobile', '$type', '$reported', '$embed', '$live', '$target_file') ON DUPLICATE KEY UPDATE
name
=VALUES('$name'), address
=VALUES('$address'), lat
=VALUES('$lat'), long
=VALUES('$lon'), description
=VALUES('$description'), mobile
=VALUES('$mobile'), type
=VALUES('$type'), reported
=VALUES('$reported'), embed
=VALUES('$embed'), live
=VALUES('$live'), img_url
=VALUES('$img_url')";
Thank You for your help!
UPDATE:
I have also tried backticking reserved words. My current SQL code is still throwing back an error.
1064 - 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 ''$name'), address=VALUES('$address'), lat=VALUES('$lat'), lon=VALUES('$lon'), de' at line 2
The updated SQL code I am using is:
INSERT INTO `xxy` (`ID`, `name`, `address`, `lat`, `lon`,
`description`, `mobile`, `type`, `reported`, `embed`, `live`,
`img_url`) VALUES('$id', '$name', '$address', '$lat', '$lon',
'$description', '$mobile', '$type', '$reported', '$embed', '$live',
'$target_file') ON DUPLICATE KEY UPDATE `name`=VALUES('$name'),
`address`=VALUES('$address'), `lat`=VALUES('$lat'),
`lon`=VALUES('$lon'), `description`=VALUES('$description'),
`mobile`=VALUES('$mobile'), `type`=VALUES('$type'),
`reported`=VALUES('$reported'), `embed`=VALUES('$embed'),
`live`=VALUES('$live'), `img_url`=VALUES('$img_url')