2016-07-23 61 views
0

我正在练习为网站构建PHP注册表单脚本。我已经完成了这个代码,但是当我点击提交按钮时,我得到了通知:只有变量应该在第13行中通过引用传递,并且我坚持要在这里做什么。任何帮助非常感谢,再次我不是一个PHP专家。只有变量应通过引用传递...在线13失败

<?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; 

?> 

这里

+0

当你得到PHP错误很好的参考http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php – Terminus

回答

2

改变这种

$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); 

错误信息是明确的,虽然你需要将这些值分配到变量,然后将它们传递

0

$ result-> bindParam(':id',$ id,PDO :: PARAM_INT);

如果字符串,你需要写
$ stmt-> bindParam( ':用户名',$ _ POST [ '用户名'],PDO :: PARAM_STR);