[英]Getting error Strict Standards: Only variables should be passed by reference in register.php on line 20
I downloaded login php script from GitHub ( Link to it ) and when I try to register, it displays me this error: Strict Standards: Only variables should be passed by reference in /homework/register.php on line 20
On login page it doesn't show any errors. 我从GitHub下载了登录php脚本( 链接到它 ),当我尝试注册时,它向我显示此错误:
Strict Standards: Only variables should be passed by reference in /homework/register.php on line 20
在登录页面上,它没有没有显示任何错误。
Code that I was using: 我正在使用的代码:
<?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 (if needed): 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());
}
Database is working fine. 数据库工作正常。 Not getting errors.
没有收到错误。
Can someone explain what is going wrong with registration? 有人可以解释注册出了什么问题吗?
When passing a value to bind_param()
, you need to pass a variable and not the return value from a function... 将值传递给
bind_param()
,您需要传递变量而不是函数的返回值...
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
to... 至...
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':password', $password);
When you see a parameter with a &
in front of it as in &$variable
in... 当您看到参数前面带有
&
的参数时,如&$variable
in ...
public bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable [, int $data_type = PDO::PARAM_STR [, int $length [, mixed $driver_options ]]] )
公共布尔PDOStatement :: bindParam(混合$ parameter,混合&$ variable [,整数$ data_type = PDO :: PARAM_STR [,整数$ length [,混合$ driver_options]]])
You need to pass a variable. 您需要传递一个变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.