Search code examples
phpdatabasemysqlipdostatements

PDOStatement wrong result on check


I am having this code:

$PDOStatement = $pdo->prepare("INSERT INTO users (ID, email, password) VALUES(?, ?, ?)");

    if($PDOStatement->execute($uuid, $email,$encrypted_password))
    {
        echo "test";
        return true;
    }

The data gets entered into the DB, but unforunetly the IF is not giving out the echo or the return.

Thanks in advance!


Solution

  • You need to pass the parameters as an array:

    if($PDOStatement->execute($uuid, $email,$encrypted_password))
    

    should be

    if($PDOStatement->execute([$uuid, $email,$encrypted_password]))
    

    (Manual: http://php.net/manual/en/pdostatement.execute.php)