我正在練習編碼,並正在使用我從YouTube上觀看的視頻製作登錄系統。當我嘗試註冊一個帳戶時,一切正常,但唯一的問題是它給了我一個小錯誤,說明這一點:嚴格標準:只有變量應該通過/home/login-name/public_html/login/register.php中的引用傳遞線9錯誤:嚴格標準:只有變量應該通過引用傳遞?
Register.php
<?php
require 'database.php';
if(!empty($_POST['username']) && !empty($_POST['password'])):
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if($stmt->execute()):
die('Success');
else:
die('Fail');
endif;
endif;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Register</title>
<meta charset=utf-8>
<link href="../css/register.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
</head>
<body>
<div class="header">
<span class="header-logo"><a href="home">Abyssal Test</a></span>
</div>
<form action="register" method="POST">
<input type="text" placeholder="Username" name="username">
<input type="password" placeholder="Password" name="password">
<input type="password" placeholder="Confirm Password" name="confirm_password">
<input type="submit" name="register" value="Register">
<span class="register-text">Already have an account? <a href="login">Login Here</a></span>
</form>
</body>
</html>
就像錯誤狀態一樣。你需要重寫'$ stmt-> bindParam(':password',password_hash($ _ POST ['password'],PASSWORD_BCRYPT));' –