1

I'm having trouble encrypting a password when adding an entry into mysql using php bound parameters. Everything works just fine with 2 bound parameters ($username and $password) being inserted directly into the username and password field. But, when I try to add a third $salt variable and insert password with the sha2 function, it won't execute correctly anymore. The code below will print to my debug console "couldn't execute" each time. Why?

$stmt = $GLOBALS['mysqli']->stmt_init();
$sql = "INSERT INTO users ( username, password ) VALUES ( ?, sha2(concat(?,?),256) ) ";
if($stmt->prepare($sql)){
    $stmt->bind_param('sss',$username,$password,$salt);
    if($stmt->execute()){
        if($stmt->affected_rows>0){ $userID=$stmt->insert_id; }
    }
    else{ wdebug("couldn't execute"); }
    $stmt->close();     
}
Andrew
  • 56
  • 6

0 Answers0