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"

SmileAshis
  • 93
  • 1
  • 5
  • 12
  • 4
    `add` is reserve word in mysql – Sadikhasan Jul 02 '14 at 05:21
  • @AshishBiswas Never forget accept/upvote if answer is helpful – Sadikhasan Jul 02 '14 at 05:48
  • possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – vhu Jul 02 '14 at 06: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. – SmileAshis Jul 02 '14 at 10:33

2 Answers2

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

Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
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.

Sadikhasan
  • 18,365
  • 21
  • 80
  • 122