本文介绍了仅变量应在第13行的...中通过引用传递.失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为网站构建PHP注册表单脚本.我已经完成了这段代码,但是当我单击提交"按钮时,我得到了通知:在第13行中,只有变量应该通过引用传递,而我在这里只能做些事情.非常感谢您的帮助,我又不是PHP专家.
I'm practicing building a PHP registration form script for a website. I have done this code, but when I click the submit button I get the notice: Only variables should be passed by reference in line 13, and I'm stuck on what to do here. Any help is greatly appreciated, again I'm not a PHP expert.
<?php
require 'database.php';
if(!empty($_POST['email']) && !empty($_POST['username']) && !empty($_POST['password'])):
//Enter the new user into the database
$sql = "INSERT INTO users (email, username, password) VALUES (:email, :username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if($stmt->execute() ):
die('Success');
else:
die('Fail');
endif;
endif;
?>
这里
推荐答案
更改此内容
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
对此
$email = $_POST['email'];
$username = $_POST['username'];
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password',$password);
尽管您需要将这些值分配给变量然后将其传递
the error message is clear though you need to assign those values into variables then pass them
这篇关于仅变量应在第13行的...中通过引用传递.失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!