php - password_hash giving error: Strict standards: Only variables should be passed by reference -
this question has answer here:
edit: issue has been resolved. did not know or think of bindvalue(), why not think duplicate question. help!
i learning how register users php , seems password_hash giving me "only variables should passed reference" error message. i've seen many people same error, not seem apply case (in opinion).
connecting database
$server = 'localhost'; $username ='root'; $password ='root'; $database = 'register_test'; try{ $conn = new pdo("mysql:host=$server;dbname=$database;" , $username, $password); } catch(pdoexception $e){ die ("connection failed" . $e->getmessage()); }
registering user
require 'database.php'; if(!empty($_post['email']) && !empty($_post['password'])): $pass = $_post['password']; $email = $_post['email']; $sql = "insert user (email, password) values (:email, :password)"; $stmt = $conn->prepare($sql); $stmt ->bindparam(':email', $email); $stmt ->bindparam(':password', password_hash($pass, password_bcrypt)); //error showns here if($stmt -> execute() ): die('success'); else: die('fail'); endif; endif;
if guys need more information please let me know.
use pdostatement::bindvalue()
instead of pdostatement::bindparam()
.
from docs:
unlike pdostatement::bindvalue(), variable bound reference , evaluated @ time pdostatement::execute() called.
so, code becomes:
$stmt->bindvalue(':email', $email); $stmt->bindvalue(':password', password_hash($pass, password_bcrypt));
the result of function cannot passed reference when e_strict
mode enabled, without triggering warning. using bindvalue()
instead, pass return value of function copy, basically.
Comments
Post a Comment