0

Hi I have the following code which seem to just want to not work, I have done code the same which has worked fine before so I don't quite know why it is not working now. It returns the error: "Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number in... "

This is the Php pdo function I call to edit the database:

public function update_email_validation($params)
{
    $stmt = $this->conn->prepare('
            UPDATE email_validation
            SET status=:status
            WHERE email=:email
            AND hash=:hash
            AND status!=:status
            LIMIT 1');

    $stmt->bindParam(':status', $params['status'], PDO::PARAM_INT);
    $stmt->bindParam(':email', $params['email'], PDO::PARAM_STR);
    $stmt->bindParam(':hash', $params['hash'], PDO::PARAM_STR);

    $stmt->execute();
    return $stmt->rowCount();
}

And then this is the call from php passing the array along:

if ($db->update_email_validation(
       ['status' => 1,
        'email' => $params['email'],
        'hash' => $params['hash']]
    ) == 0)
{

}

thanks in advance.

Rick James
  • 135,179
  • 13
  • 127
  • 222
K. Bishop
  • 72
  • 6
  • 3
    4 placeholders + 3 variables = bad time – bassxzero Sep 23 '16 at 22:12
  • @bassxzero is right. You're using 4 placeholders in your query but only pass 3 values to them. I understand 2 placeholders are the same but if I remember correctly, PDO doesn't recognise that. Try changing the second and `:status` with something else and pass the same value to it – icecub Sep 23 '16 at 22:16
  • 1
    turn on pdo emulation – bassxzero Sep 23 '16 at 22:28
  • Sadly, it isn't mandatory for PDO drivers to support name-based parameters that are used more than once (call it bug of feature). In MySQL they work or not depending on whether you use native or emulated prepared statements. – Álvaro González Sep 27 '16 at 16:31

0 Answers0