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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.