Search code examples
phpmysqlpdoexecution

Whats wrong with this Mysql PDO execution that makes it not execute?


This query is not executing, and I'm sure its going over the code, it just doesn't update the row.

$statement = $db->prepare("UPDATE users SET data=:data WHERE id=:id");
$statement->execute(array(':data' => $data, ':id' =>     $_REQUEST['user_id']));

What could be the problem? I am 100% that the $_REQUEST['user_id'] is valid and exists in the DB, and that data contains something as well. I'm really clueless why it wont execute.


Solution

  • Try binding your params first:

    $statement = $db->prepare("UPDATE users SET data=:data WHERE id=:id");
    
    $statement->bindValue(':data', $data, PDO::PARAM_STR);
    $statement->bindValue(':id',  $_REQUEST['user_id'], PDO::PARAM_INT);
    
    $statement->execute();