By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Can't find my Query syntax error

P: 1
Maybe my eyes are just tired...
Can anyone help me spot the syntax error in this code:
[PHP]$sql = "INSERT INTO `images` ( 'imgid' , 'lstid' , 'descrip' )
VALUES (
'', '" ."$pid". "', ''
);";


$result = @mysql_query("$sql") or die(mysql_error());[/PHP]

I get the error:

You have an error in your SQL syntax near ''imgid' , 'lstid' , 'descrip' ) VALUES ( '', '15', '' )' at line 1

thanks in advance for your help!!!
May 23 '07 #1
Share this Question
Share on Google+
1 Reply


pbmods
Expert 5K+
P: 5,821
Use backticks (`) for column names and single quotes (') for values:

Expand|Select|Wrap|Line Numbers
  1. $sql = "INSERT INTO `images` (`descrip`) VALUES ('$pid')";
  2.  
  3. if(! ($result = mysql_query($sql)))
  4.     throw new Exception(mysql_error());
  5.  
Couple of minor things:
  • If a value will be null, you don't have to include it in the list of fields.
  • You're not supposed to end your queries with a semi-colon when you pass them to mysql_query. Don't believe me? http://php.net/mysql_query. Look under "query".
May 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.