I have only a little experience with PHP having mostly used straight HTML and CGI/Perl.
I have encountered the following error message when running a query and cannot resolve it, which is a little perplexing!
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in [absolute path to file] on line 120
Line 120 of file=
[CODE]$numrows = mysqli_num_rows($result);[/CODE]
The REALLY puzzling thing is that when I run the page and query on my localhost computer (PHP 5.4.7; MySQL 5.5.27) it runs fine and returns a list, just as it should. It's only when the files are transferred to and run on the remote server (PHP 5.2 or 5.4, MySQL 5.0 - 1and1.com) that it fails to run (I have changed all the database accesses and passwords!).
I'm sure it's something simple and stupid, but I'm at a loss! Assistance would be appreciated!!
Code is below.
Thank you!!
<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
if (isset($_POST['submitted'])) {
// connect to database
include('../connect.php');
$category = $_POST['category'];
$criteria = $_POST['criteria'];
$query = "SELECT * FROM erstallions WHERE $category LIKE '%".$criteria."%'";
$result = mysqli_query($dbcon, $query);
$numrows = mysqli_num_rows($result);
// If the query has results ...
if ($numrows > 0)
{
// ... print out a header
if ($criteria == '')
{
print "<br /><center><font size=\"+2\"><b>Stallion Listing</b></font></center><br>";
}
else
{
print "<center><font size=\"+2\"><b>Information about the stallion '$criteria'<br>(Frozen by <i>Equine-Reproduction.com LLC</i>)</b></font></center><br>";
};
// and start a <table>.
print "\n<table width=\"100%\" border=\"1\" align=\"center\">\n<tr>" .
"\n\t<th>Stallion Name</th>" .
"\n\t<th>Owner</th>" .
"\n\t<th>Breed</th>" .
"\n\t<th>Reg. Number</th>" .
"\n\t<th>Birth Date/Year</th>\n</tr>";
// Fetch each of the query rows
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
// Print one row of results
print "\n<tr>\n\t<td><a href=\"StallionDetails.php?StallionName={$row["StallionName"]}\" target=\"_blank\">{$row["StallionName"]}</a></td>" .
"\n\t<td>{$row["OwnerName"]}</td>" .
"\n\t<td>{$row["StallionBreed"]}</td>" .
"\n\t<td>{$row["StallionRegNo"]}</td>" .
"\n\t<td><center>{$row["DoB"]}</center></td>\n</tr>";
} // end while loop body
// Finish the <table>
print "\n</table>";
} // end if $rowsFound body
// Report how many rows were found
print "<center>{$numrows} record(s) found matching your criteria</center><br>";
} //End of main if statement
?>