PDO Update problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Wed Nov 14, 2012 3:48 am

PDO Update problem

Postby Siggles » Wed Nov 14, 2012 3:51 am

Hi, I tried the follwoing code and have similr code working in my script with SELECT and INSERT queries but get an error with this UPDATE query. Can you help? What am I doing wrong?

Code: Select all

function updateUserField($username, $field, $value){
   $query = "UPDATE ".TBL_USERS." SET :field = :value WHERE username = :username";
   $stmt = $this->connection->prepare($query);
   return $stmt->execute(array(':field' => $field, ':value' => $value, ':username' => $username));

The error is:

Code: Select all

Fatal error: Uncaught exception 'PDOException' with message '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 ''userid' = '9640b0e92ce508f2b4a972ed3a50cc0b' WHERE username = 'billy'' at line 1' in /home/*****/public_html/login/include/database.php:223 Stack trace: #0 /home/****/public_html/login/include/database.php(223): PDOStatement->execute(Array) #1 /home/******/public_html/login/include/session.php(184): MySQLDB->updateUserField('billy', 'userid', '9640b0e92cess8f...') #2 /home/*****/public_html/login/process.php(60): Session->login('billy', 'P4dsdsd', false) #3 /home/*****/public_html/login/process.php(21): Process->procLogin() #4 /home/angry/public_html/login/process.php(236): Process->Process() #5 {main} thrown in /home/*****/public_html/login/include/database.php on line 223

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests