Jump to content
Larry Ullman's Book Forums

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in


Recommended Posts

I'm trying to run a query of existing employee records in order to update their information, and am receiving the error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/schill54/public_html/Capstone/htdocs/Home/updateform.php on line 8

Below is my script. I've tweaked the query several times with no luck. Originally I had it set to SELECT * from my users table but then realized there was 1 column that I didn't want it to return and therefore I didn't account for it in my form, so then listed the desired columns individually but still getting the error. From the google searching I've done so far I realize there is probably still something wrong with my query but can't figure out what it is.

<?php
{
	include ("../includes/header.php");
	require_once ('../../mysqli_connect.php');
	$lname=$_GET['last_name']; 
	$query = "SELECT first_name, last_name, phone, username, pass, admin FROM users WHERE last_name='$lname'"; 
	$result = mysqli_query ($dbc, $query);
	$num = mysqli_num_rows($result);
	if ($num > 0) { // If it ran OK, display all the records.
		while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
?>
			<form action="updatemp.php" method="post">
			<p>First Name: <input name="text" size=30 value="<? echo $row['first_name']; ?>"></p>
			<p>Last Name: <input name="text" size=30 value="<? echo $row['last_name']; ?>"></p>
			<p>Phone Number: <input name="text" size=30 value="<? echo $row['phone']; ?>"></p>
			<p>User Name: <input name="text" size=30 value="<? echo $row['username']; ?>"></p>
			<p>Password: <input name="text" size=30 value="<? echo $row['pass']; ?>"></p>
			<p>Admin Access?: <input name="text" size=30 value="<? echo $row['admin']; ?>"></p>
			</form>
<?
		} //end while statement
	} //end if statement
	mysqli_close($dbc);
	//include the footer
	include ("../includes/footer.php");
}
?>

 

Link to comment
Share on other sites

Yeah, this error means the query returned false instead of 0 or more results, which means the query has an error in it. Most likely there's a mismatch between the query and how the table is defined. The easiest way to know the specific problem is to print out the MySQL error. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...