Sunday, 20 November 2016

Resolving a Boolean error in 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

Answer



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().


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...