douce1368 2014-03-21 03:50
浏览 41
已采纳

解决Php mysql中的布尔错误[重复]

Im finding a way to resolve the boolean error it seems that I cannot fix the error, I dont know what does the error mean, I've asked for help but it seems like it doesn't work properly, Please help.

Php code:

$dbcon=mysqli_connect("localhost","root","","admin");

if(mysqli_connect_errno()){

echo "Error".mysqli_connect_error();
}

$username = mysqli_real_escape_string($dbcon,$_POST['username']); /* prevents a bit of SQL injection */
$password = mysqli_real_escape_string($dbcon,$_POST['password']); /* prevents a bit of SQL injection */
$username1 = mysqli_real_escape_string($dbcon,$_POST['username1']); /* prevents a bit of SQL injection */
$password1 = mysqli_real_escape_string($dbcon,$_POST['password1']); /* prevents a bit of SQL injection */



$qry=mysqli_query($dbcon,"SELECT * FROM admininfo WHERE username='$username' AND password='$password' AND type1='customer'");
$qryadmin=mysqli_query($dbcon,"SELECT * FROM customerinfo WHERE username1='$username1' AND password1='$password1' AND type='admin'");

if(mysqli_num_rows($qry)==1){
header("LOCATION:menu1.php");
}

else if(mysqli_num_rows($qryadmin)==1){
header("LOCATION:menu.php");
}

else {
echo "Error! No user found.";
}  

Error is:(between the if else statement, First error:if(mysqli_num_rows($qry)==1) Second error: else if(mysqli_num_rows($qryadmin)==1) Error description below )

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\addeditdelete1\loginExec.php on line 34

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\addeditdelete1\loginExec.php on line 38
</div>
  • 写回答

1条回答 默认 最新

  • dongxianghuan3587 2014-03-21 03:54
    关注

    Upon failure, mysqli_query returns false, so you should probably check if it is false or not before supplying it as a parameter to mysqli_num_rows().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导