我已经尝试了一切,找出为什么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