我从GitHub (Link to it)下载了登录php脚本,当我尝试注册时,它会显示这个错误:登录页面上的Strict Standards: Only variables should be passed by reference in /homework/register.php on line 20
没有显示任何错误。
我使用的代码如下:
<?php
session_start();
if( isset($_SESSION['user_id']) ){
header("Location: /");
}
require 'database.php';
$message = '';
if(!empty($_POST['email']) && !empty($_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() ):
$message = 'Successfully created new user';
else:
$message = 'Sorry there must have been an issue creating your account';
endif;
endif;
?>
<!DOCTYPE html>
<html>
<head>
<title>Register Below</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<link href='http://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="header">
<a href="/">Homework</a>
</div>
<?php if(!empty($message)): ?>
<p><?= $message ?></p>
<?php endif; ?>
<h1>Register</h1>
<span>or <a href="login.php">login here</a></span>
<form action="register.php" method="POST">
<input type="text" placeholder="Enter your email" name="email">
<input type="password" placeholder="and password" name="password">
<input type="password" placeholder="confirm password" name="confirm_password">
<input type="submit">
</form>
</body>
</html>
database.php (如果需要):
<?php
$server = 'localhost';
$username = 'my_username';
$password = 'my_password';
$database = 'my_dbname';
try{
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
} catch(PDOException $e){
die( "Connection failed: " . $e->getMessage());
}
数据库工作正常。没有收到错误。
有人能解释一下注册出了什么问题吗?
发布于 2018-06-16 23:48:49
在将值传递给bind_param()
时,您需要传递一个变量,而不是函数的返回值...
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
为了..。
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':password', $password);
当您看到前面有一个&
的参数时,如&$variable
in...
公共布尔PDOStatement::bindParam ( mixed $parameter,mixed &$variable [,int $data_type = PDO::PARAM_STR [,int $length,mixed $driver_options ]] )
您需要传递一个变量。
https://stackoverflow.com/questions/50889344
复制相似问题