cooldude832 Posted June 12, 2007 Share Posted June 12, 2007 I have this code: $fields = "Adnumber, Creator, Adtitle, Aptytpe, Apbrand, Apcondition, Price, Priceshow, Imgcount, Apweb, Apdescription, Apcity, Apstate, Apship, CDate, MDate, Show"; $values = "' \"$querynumber\",\"$user\",\"$adtitle\",\"$aptype\",\"$brand\",\"$condition\",\"$pirce\", \"$pricedisplay\",\"$imgcount\",\"$website\",\"$comments\",\"$location\",\"$state\",\"$shipping\", \"$date\",\"\",\"0\"'"; $table = "apparel_ads"; mysql_query("INSERT INTO $table ($fields)VALUES($values)") or die(mysql_error()); and i get this error and its driving me crazy cause it doesn't make sense: 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 'Show)VALUES(' "89XST3970GYN26","testuser","Title","Type","Brand thanks in advance for help Quote Link to comment https://forums.phpfreaks.com/topic/55188-solved-mysql-query-error-not-making-sense/ Share on other sites More sharing options...
btherl Posted June 12, 2007 Share Posted June 12, 2007 Try printing out your query and looking. You have your values inside both single AND double quotes there, which certainly won't help. But the error reported appears to be earlier, near "Show". Try putting "Show" inside backquotes like this: `Show` The other thing I would change is this: $values = "'$querynumber', ... "; Then instead of calling the query directly, put it in a variable first and print it out so you can inspect it. Quote Link to comment https://forums.phpfreaks.com/topic/55188-solved-mysql-query-error-not-making-sense/#findComment-272798 Share on other sites More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 For starters, you can make your values alot easier to read by using... $values = "'$querynumber','$user','$adtitle','$aptype','$brand','$condition','$pirce', '$pricedisplay','$imgcount','$website','$comments','$location','$state','$shipping', '$date','','0'"; The word SHOW is also a reserved word so it needs to be surrounded in backticks. eg `show` Then need to format your query to read.... mysql_query("INSERT INTO $table ($fields) VALUES ($values)") or die(mysql_error()); Notice the spaces around VALUES ? Quote Link to comment https://forums.phpfreaks.com/topic/55188-solved-mysql-query-error-not-making-sense/#findComment-272800 Share on other sites More sharing options...
cooldude832 Posted June 12, 2007 Author Share Posted June 12, 2007 another thing to put in the archive apparently show is one of those naynay words in column titles sorta like index the `show` did it thanks Quote Link to comment https://forums.phpfreaks.com/topic/55188-solved-mysql-query-error-not-making-sense/#findComment-272801 Share on other sites More sharing options...
cooldude832 Posted June 12, 2007 Author Share Posted June 12, 2007 I know i can use single quotes, but i guess its justa habit of mine to use double quotes on everything and not have to worry about single quotes like in an array key or something. Quote Link to comment https://forums.phpfreaks.com/topic/55188-solved-mysql-query-error-not-making-sense/#findComment-272803 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.