resdog Posted June 24, 2008 Share Posted June 24, 2008 Hello everyone. Had a bit of a stumper to me, maybe someone can help. I have a basic php site, with a MySQL database. The database has a table, "vendortrack", and the rows are "refnum ,order ,tracking ,shipcost ,dateshipped". I'm trying to do a simple INSERT INTO php command with posted variables, as follows: $q = "INSERT INTO vendortrack (refnum, order, tracking, shipcost, dateshipped) VALUES ('$refnum','$order','$tracking','$shipcost','$todaysDate')"; $result = mysql_query($q) or die(mysql_error()); When I run this on the server, I get this error: 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 'order ,tracking ,shipcost ,dateshipped) VALUES ('ddf','2252','1Zkdikd','2.25' at line 1 I don't see what is wrong. So I went to PHP MyAdmin and ran a smiliar query to see what the SQL looked like. Everything was the same, except there are these weird kind of quotes around the rows: `refnum` ,`order` ,`tracking` ,`shipcost` ,`dateshipped` They aren't the apostrophe character, but I don't know what they are (apostrophe: ' that other character: ` . I replaced that line with the line from phpMyAdmin, and the script works great! I've never had to add the quote things before when I did INSERT INTO, I've just had to name the rows. Does anyone see what my problem is, or what those apostrophe looking characters are? Thanks in advance for your help! Link to comment https://forums.phpfreaks.com/topic/111674-solved-php-insert-errorwhat/ Share on other sites More sharing options...
trq Posted June 24, 2008 Share Posted June 24, 2008 order is a special keyword in sql. Your confusing the mysql database. You can use `backticks` to escape special words in mysql, though its best (if possible) to chnage your field names. Link to comment https://forums.phpfreaks.com/topic/111674-solved-php-insert-errorwhat/#findComment-573216 Share on other sites More sharing options...
resdog Posted June 24, 2008 Author Share Posted June 24, 2008 THANK YOU! THANK YOU! THANK YOU! Link to comment https://forums.phpfreaks.com/topic/111674-solved-php-insert-errorwhat/#findComment-573218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.