Jump to content

Quick error, php mysql


Darnel

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.

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

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.