0

I there any problem on my code??? If its ok then why i am always get this error

PDOException: SQLSTATE[42000]: Syntax error or access violation: 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 'add = 'Myaddress' WHERE id = '' at line 7 in C:****\class\class.admin.php on line 160

Here is my Code:

function EditClient($uname,$email,$pname,$cname,$mob,$add,$cid)
    {
        $query = $this->dbh->prepare("
                UPDATE client SET 
                uname = :username,
                email = :email,
                pname = :pname,
                cname = :cname,
                mob = :mob,
                add = :addr
                WHERE id = :id ");


        $query->execute(array(
                ':username' => $uname,
                ':email' => $email,
                ':pname' => $pname,
                ':cname' => $cname,
                ':mob' => $mob,
                ':addr' => $add,
                ':id' => $cid
                )); //here is the line 160

        return $query->rowCount();
    }

Where the value of $cid is "Myaddress"

4
  • 4
    add is reserve word in mysql Commented Jul 2, 2014 at 5:21
  • @AshishBiswas Never forget accept/upvote if answer is helpful Commented Jul 2, 2014 at 5:48
  • possible duplicate of Syntax error due to using a reserved word as a table or column name in MySQL Commented Jul 2, 2014 at 6:00
  • Yep, after got this fix now i understand its look like duplicate of this question which you mentioned, but at the time when i was posting this never thought about reserve word. BTW thanks. Commented Jul 2, 2014 at 10:33

2 Answers 2

2

The error is caused by using a reserved word ADD

add = :addr

You need to back-tick it

`add` = :addr

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Sign up to request clarification or add additional context in comments.

1 Comment

:P Thanks. I have totally forget this.
2

In mySql add is reserve word so you need to change

add = :addr

to

`add` = :addr

add back-tick on add keyword as mentioned above.

Check Manual for Reserve word in mysql.

Comments

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.