0

hi to all m using the following query:

$rows = mysql_query("UPDATE admin SET create ='".$close."' WHERE id=".$id) or die(mysql_error());

but i got the following error: 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 'create ='0' WHERE id=6' at line 1

help me plz in this regard thnx in advance

1
  • @KA_lin Don't you mean BEGIN it... Commented Oct 12, 2012 at 14:52

2 Answers 2

8

create is a reserved word. You'll have to escape it:

UPDATE admin SET `create`=...
                 ^-     ^-
Sign up to request clarification or add additional context in comments.

2 Comments

i have change the query $rows = mysql_query("UPDATE admin SET 'create' ='".$close."' WHERE id=".$id) or die(mysql_error()); but the error is same
wrong quotes. use backticks: ` . normal quotes, ' turn things into strings.
2

You need to quote your query correctly with backticks (`) as create is a reserved keyword in MySQL.

$rows = mysql_query("UPDATE admin SET `create` = '".$close."' WHERE `id` = ".$id) or die(mysql_error());

I highly recommend using PDO.

6 Comments

id doesn't need to be quoted. it's not a reserved word.
True but it's consistent. I would always use PDO anyway.
Actually, yes you are right. I was thinking of ORM behaviour! Still PDO is the way forward.
i have change the query $rows = mysql_query("UPDATE admin SET 'create' ='".$close."' WHERE id=".$id) or die(mysql_error()); but the error is same
You are using the wrong type of quoting. You should be using backticks `. Copy my code posted in the answer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.