If I run this I get the following error:
Notice: Only variables should be passed by reference in /var/www/interface/register.php on line 11 Success
I dont know how to fix that. It's still successful and the data is hashed in the database, but I don't want this notice.
$sql = " INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if ($stmt->execute()) :
die('Success');
else:
die('Fail');
endif;
Thanks in advance.
You cannot do password_hash($_POST['password'], PASSWORD_BCRYPT) inside bindParam, because password_hash returns a string, do:
If you wish to leave the values there use bindValue:
because it allows varibles by reference.
Explanation:
bindParam expects a variable or const it can't be a primitive type such as a string or an int, ..., explicitly (ex: "some_hardcoded_string") neither can it be a function that returns one of this types.
bindValue can receive references and primitive types as an argument.
Examples for both:
SHA1 is returns a value, it could be a number 12345 (let's say for the sake of the example)
or a string.
retated questions: