注意:在第12行的C:\xampp\htdocs\auth\register.php中,只能通过引用传递变量
它成功地在数据库中添加了用户和密码,但给出了以下错误注意:在第12行的C:\xampp\htdocs\auth\register.php中,只能通过引用传递变量,php,Php,它成功地在数据库中添加了用户和密码,但给出了以下错误 在第12行的C:\xampp\htdocs\auth\register.php中,只能通过引用传递变量 bindParam的格式如下所示: <?php require 'database.php'; if (isset($_POST['email']) && isset($_POST['password'])): // Enter the new user in the database
在第12行的C:\xampp\htdocs\auth\register.php中,只能通过引用传递变量
bindParam的格式如下所示:
<?php
require 'database.php';
if (isset($_POST['email']) && isset($_POST['password'])):
// Enter the new user in the database
$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() ):
die('Success');
else:
die('Fail');
endif;
endif;
?>
请注意,这部分mixed&$variable
是通过引用传递的。
要解决此问题,只需更改:
public bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable [, int $data_type = PDO::PARAM_STR [, int $length [, mixed $driver_options ]]] )
致:
由于您随后通过引用传递变量本身,而不仅仅是
password\u hash()
返回的字符串,错误在哪里?在C:\xampp\htdocs\auth\register.php的第12行“第12行”是什么?哦,我现在明白了。。。谢谢:)
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':password', $password);