Click here to Skip to main content
14,695,620 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the following php funtion to check for a file on the database
function getAll($what, $tableName, $where=null)
{
	global $db_conn;
	if($where == null)
	{
		$query = mysqli_query($db_conn, "SELECT  $what  FROM `$tableName`");
		return $query;
	}
	else
	{
		$query = mysqli_query($db_conn, "SELECT  $what  FROM `$tableName` WHERE  $where");
		return $query;
	}
	mysqli_close();
}




function getSingle($what, $tableName, $where=null)
{
	$result = getAll($what, $tableName, $where);
	$row = mysqli_fetch_array($result);
	return $row["$what"];
	mysqli_close();
}

function getCount($tableName, $where=null)
{
	$result = getAll('*', $tableName, $where);
	return mysqli_num_rows($result);
	mysqli_close();
}

$error =false;


if(isset($_POST['login']))
{
	$status = 'admin';
	$email_user='';
	$own_email=$_POST['email_user'];
	$adm_email=$_POST['email_user'];
	$Password = $_POST['Password'];
	$staf_username = $_POST['email_user'];
	$stu_username = $_POST['email_user'];
	$own_email = filter_var($email_user, FILTER_VALIDATE_EMAIL);
	$Password = hash('sha256','password');
	$Password = strip_tags(addslashes($Password));

	$count = getCount('owners_db', "own_email ='$own_email'");
	$count1 = getCount('staff_db', "staf_username ='$staf_username' ");
	$count2 = getCount('student_db', "stu_username ='$stu_username' ");
	// this is for the admin
	$count3 = getCount('admin_db', "adm_email ='$adm_email'");
	
	if ($count != 0) {
		$own_id = getSingle('own_id', 'owners_db', "own_email = '$own_email' AND Password = '$Password'");
		return;
	}
	elseif($count == 0){
		$error=true;
		$errormsg1= '<div id="success" class="alert red">Invalid email or password!</div>';
		return;
	}
	elseif($count == 1){

		$_SESSION['own_email'] = $own_email;
		$update = update('owners_db', "last_login=now()", "own_email='$own_email'");

		header('location: owners_dashboard');
		return;
	}// count



this is the error am getting please i need help 

<pre>Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\altech-school\server\dbase\database.php on line 74

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\altech-school\server\dbase\database.php on line 74

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\altech-school\server\dbase\database.php on line 74


What I have tried:

this is the error am getting please i need help

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\altech-school\server\dbase\database.php on line 74

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\altech-school\server\dbase\database.php on line 74

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\altech-school\server\dbase\database.php on line 74
Posted
Updated 22-Aug-20 22:37pm

It's not an error but warning.

To remove it (and as a best practice), you should check $result of mysqli_query before passing it to mysqli_num_rows

Reference: PHP: mysqli::query - Manual[^]
   
Comments
sammy egwu 22-Aug-20 17:46pm
   
function getCount($tableName, $where=null)
{
$result = getAll('*', $tableName, $where);
return mysqli_num_rows($result);
mysqli_close();
}
please the error is pointing on this file name above database.php
Sandeep Mewara 22-Aug-20 17:48pm
   
whats getAll() definition?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900