I checked similar questions here but it couldn't solve my problem. I'm creating a php user registration form and when I try to register I get this error: Strict standards: Only variables should be passed by reference in F:\wamp64\www\loginegister.php on line 14
I tried it on PHP version 5.6 and 7.0 but the error is the same.
Line 14 is this:
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
Here is my entire code:
<?php
$server = 'localhost';
$username = 'root';
$password = 'root';
$database = 'auth';
try{
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
} catch(PDOException $e) {
die( "Connection failed: " . $e->getMessage());
}
$message = '';
if(!empty($_POST['email']) && !empty($_POST['password'])):
$sql = "INSERT INTO users (email, password) VALUES (:email, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute()):
$message = 'Successfully created new user';
else:
$message = 'Sorry there must have been an issue creating your account';
endif;
endif;
?>
Any help is appreciated, thanks.
try
$pass = ':password';
$phash = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam($pass, $phash);