2016-11-20 64 views
0

我在這裏查了類似的問題,但它不能解決我的問題。我正在創建一個php用戶註冊表單,當我嘗試註冊時,我得到這個錯誤:嚴格標準:只有變量應該通過引用傳遞給第14行的F:\ wamp64 \ www \ login \ register.php只有變量應該通過引用傳遞php

我在PHP版本5.6和7.0上試過,但是錯誤是一樣的。

14號線是這樣的:

$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT)); 

這裏是我的全部代碼:

<?php 
$server = 'localhost'; 
$username = 'root'; 
$password = 'root'; 
$database = 'auth'; 

try{ 
    $conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password); 
} catch(PDOException $e) { 
    die("Connection failed: " . $e->getMessage()); 
} 

$message = ''; 

if(!empty($_POST['email']) && !empty($_POST['password'])): 

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

?> 

任何幫助表示讚賞,感謝。

回答

0

嘗試

$pass = ':password'; 
$phash = password_hash($_POST['password'], PASSWORD_BCRYPT); 

$stmt->bindParam($pass, $phash); 
+0

感謝您的答覆,但它給了我2個錯誤:注意:未定義指數:密碼F:\ wamp64 \第5行,並警告WWW \登錄\ register.php:password_hash( )期望至少2個參數,1給出在第5行F:\ wamp64 \ www \ login \ register.php – PapT

+0

我編輯了我的代碼,試試這個 –

+0

謝謝。對於$ phash – PapT

相關問題