【发布时间】:2017-04-03 19:32:18
【问题描述】:
我在这里检查了类似的问题,但它无法解决我的问题。我正在创建一个 php 用户注册表单,当我尝试注册时出现此错误:严格标准:只有变量应该在第 14 行的 F:\wamp64\www\login\register.php 中通过引用传递
我在 PHP 5.6 和 7.0 版本上试过,但错误是一样的。
第 14 行是这样的:
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
这是我的完整代码:
<?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;
?>
感谢您的帮助。
【问题讨论】:
标签: php