Jump to content

Recommended Posts

Hi, I've been trying to find the syntax error with no luck. Keep getting error 1064. I'm not used to this format so not sure what goes where. Its driving me crazy :'( can any one point me in the right direction?

 

$sql3= " UPDATE ".PROJECT_TO
  ." SET to_user ="
  ."CONCAT_WS(',','".$post['name']."', to_user),"
  ." count   =   'count +1' "
  ." WHERE project_to_id = '".$project_id." '";

 

Thanks :-\

Link to comment
https://forums.phpfreaks.com/topic/274129-quick-error-php-mysql/
Share on other sites

Database error: Invalid SQL: UPDATE project_to_user SET to_user =CONCAT_WS(',','demo1', to_user), count = 'count +1' WHERE project_to_id = '1 ' MySQL Error: 1064 (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 'count = 'count +1' WHERE project_to_id = '1 '' at line 1) Session halted.

Edited by Darnel

Count is a restricted keyword. You can't use it as a column name without using backticks. It's best to change the column name.

 

ALSO: 'count + 1' is literally the string "count + 1".

 

PPS: Don't put numbers in quotes in SQL.

Edited by Jessica

There's also a couple other problems: count='count+1' will actually try to set the count to the string "count+1", then to fix that you'll put the quotes around the 'count' but you'll be using the wrong quotes (backticks ` are for names, apostrophes ' and quotes " are for strings), and there shouldn't be quotes around the project_to_id number because numbers don't get quotes.

And that $post value better be escaped.

Thanks, Iv'e changed the name and removed quotes. But still getting error.

 

$sql3= " UPDATE ".PROJECT_TO
  ." SET to_user ="
  ."CONCAT_WS(',','".$post['name']."', to_user),"
  ." show = show +1 "
  ." WHERE project_to_id = ".$project_id." ";

 

This line causes the error (...syntax to use near 'show = show +1 WHERE project_to_id = 2' at line 1))

." show = show +1 "

 

What am I missing?

That's one reason I always use compound words for column names, i.e. "ShowCount". It is much more unlikely to be a reserved word (and unlikely to become a reserved word in a future release). And never, never let any tool put backticks in your CREATE TABLE statements (I still build mine by hand), if the CREATE had failed you would have solved this problem hours ago.

That's one reason I always use compound words for column names, i.e. "ShowCount". It is much more unlikely to be a reserved word (and unlikely to become a reserved word in a future release). And never, never let any tool put backticks in your CREATE TABLE statements (I still build mine by hand), if the CREATE had failed you would have solved this problem hours ago.

 

Thanks for the advice, ill know in the future

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.