[英]Why isn't PHP's “password_hash” returning a string?
<?php
$connection=new PDO("mysql:host=localhost;dbname=userdata", "secure_credentials", "battery_staple");
$user=$_POST['username1'];
$pass=$_POST['password1'];
$snip=mb_substr($user, 0, 3);
$pass=password_hash($pass, PASSWORD_BCRYPT);
$user_query=$connection->prepare("INSERT INTO login (email, password, semod, snippet) VALUES (:email, :password, :semod, :snippet)");
$user_query->bindParam(':email', $user);
$user_query->bindParam(':password', $pass);
$user_query->bindParam(':semod', "false");
$user_query->bindParam(':snippet', $snip);
$user_query->execute;
(密碼已更改)
我上面的PHP代碼遇到一個小問題,無論何時執行,我都會收到此錯誤:
致命錯誤:無法 在行 [##:[位置]中的引用中傳遞參數2。
環顧四周,在不使用變量的情況下直接傳遞字符串/整數時,這似乎是一個問題。 但是, password_hash()
返回一個字符串,因此我被認為它沒有返回字符串。 這個問題可能是什么問題?
您的錯誤在此行上:
$user_query->bindParam(':semod', "false");
您需要使用bindValue
。
$user_query->bindValue(':semod', "false");
bindParam
通過引用傳遞第二個參數,因此它必須是變量,而不是文字。
另外,不需要綁定已知值。 您可以輕松地將文字'false'
字符串添加到語句查詢中,即
"INSERT INTO login (email, password, semod, snippet) VALUES (:email, :password, 'false', :snippet)"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.