Jump to content

mysqli_num_rows() expects


damiendarien

Recommended Posts

trying to figure this problem out. sucks being a newbie maybe i will gain enough knowledge to be able to help out others in the near future.

<?php
session_start();

$DBConnect = @mysqli_connect("localhost", "**********", "**********")
Or die("<p>Unable to connect to the database server.</p>"
	. "<p>Error code " . mysqli_connect_errno()
	. ": " . mysqli_connect_error()) . "</p>";
$DBName = "skyward_aviation";
@mysqli_select_db($DBConnect, $DBName)
Or die("<p>Unable to select the database.</p>"
	. "<p>Error code " . mysqli_errno($DBConnect)
	. ": " . mysqli_error($DBConnect)) . "</p>";

$CustomerName = "";
if (isset($_COOKIE['customerName']))
$CustomerName = $_COOKIE['customerName'];

$TableName = "mileage";
$Mileage = 0;
$SQLstring = "SELECT SUM(mileage) FROM $TableName WHERE
flyerID='{$_SESSION['flyerID']}";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
if (mysqli_num_rows($QueryResult) > 0) {
		$Row = mysqli_fetch_row($QueryResult);
		$Mileage = number_format($Row[0], 0) ;
		mysqli_free_result($QueryResult);
}

mysqli_close($DBConnect);

?>

 

i know its a simple stupid error but cant remember nor figure it out. HERES THE ERROR

 

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\PHP_Projects\Chapter.10\FrequentFlyerClub.php on line 23

Link to comment
Share on other sites

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

 

Your result is a boolean on a select. This means you're receiving FALSE on an error.

 

Try adding a check to your $result variable as such:

 

$SQLstring = "SELECT SUM(mileage) FROM $TableName WHERE	flyerID='{$_SESSION['flyerID']}";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
if ($QueryResult === false){
   echo mysql_error($DBConnect);
}

 

 

I can tell you now, your missing a single quote at the end of your SQL statement.  flyerID='{$_SESSION['flyerID']}'";

 

 

Link to comment
Share on other sites

You haven't constructed your query correctly. You have a missing ' at the end of your query

$SQLstring = "SELECT SUM(mileage) FROM $TableName WHERE

flyerID='{$_SESSION['flyerID']}'";

 

However you probably don't need to to have the quotes wrapped around {$_SESSION['flyerID']}. If that variable only contains numbers. Only strings should be wrapped in quotes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.