Jump to content

[SOLVED] mysql query error not making sense


cooldude832

Recommended Posts

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

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.

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 ?

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.