damiendarien Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212800-mysqli_num_rows-expects/ Share on other sites More sharing options...
objnoob Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212800-mysqli_num_rows-expects/#findComment-1108444 Share on other sites More sharing options...
wildteen88 Posted September 7, 2010 Share Posted September 7, 2010 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 https://forums.phpfreaks.com/topic/212800-mysqli_num_rows-expects/#findComment-1108477 Share on other sites More sharing options...
damiendarien Posted September 8, 2010 Author Share Posted September 8, 2010 Thanks both of you. That solved it. like i said i knew it would be something simple that i was overlooking. Thanks again. Link to comment https://forums.phpfreaks.com/topic/212800-mysqli_num_rows-expects/#findComment-1108519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.