我已經嘗試了一切,找出爲什麼mysqli_query失敗。任何人都可以闡明我做錯了什麼。將有可能我不再連接到dababase?!!先謝謝你!爲什麼mysqli_query失敗 - 返回資源時,它應該返回資源
function email_exists($email){
$email = sanitize($email);
$db = new mysqli('localhost','root','','secured_login');
if($db->connect_errno){
$connect_error = 'Sorry, we are experiencing connection problems.';
die ($connect_error);
}
return (mysql_result(mysqli_query($db, "SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email'"), 0) == 1) ? true : false;
}
錯誤
Warning: mysql_result() expects parameter 1 to be resource, object given in....
替代解決方案使用mysqli_fetch_row(); < -----以下替代有效嗎?
function email_exists($email){
$email = sanitize($email);
$db = new mysqli('localhost','root','','secured_login');
if($db->connect_errno){
$connect_error = 'Sorry, we are experiencing connection problems.';
die ($connect_error);
}
$query = "SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email'";
if ($result = mysqli_query($db, $query)){
while ($result= mysqli_fetch_row($result)){
return ($result);
}
}
}
任何反饋意見是讚賞!
不錯,但你應該解釋爲什麼而不是盲目提供解決方案。另外,解釋'mysqli_fetch_ *'可能是個好主意。 –
有一些可以學習有關php的知識。謝謝您的意見! – user3001162