2016-07-23 69 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);

相關問題