Hi everybody,
I'm having some difficulties with mysql_num_rows( ) on line 26. I keep getting a warning that the supplied argument is not a valid MySQL result resource. What does that even mean!? I get the same warning on line 51. Can somebody fill me in on why this comes up and what I should do to fix it?
Thanks!
<?php
$find=$_POST['find'];
$name=trim($_POST['name']);
if (!$name) {
echo 'You have not entered a name. Please go back and try again.';
exit;
}
$db = mysql_connect('localhost', 'xxx', 'xxx', 'Premiere');
if (!$db) {
die('Could not connect to the database, error # ' . mysql_error() );
} else
echo 'The mysql_connect succeeded'."<br />";
if ($find == a) {
$query = "SELECT BALANCE, CREDIT_LIMIT FROM Premiere.CUSTOMER WHERE ".$find." LIKE '%".$name."%'";
} if ($find == b){
$query = "SELECT * FROM Premiere.ORDERS, Premiere.CUSTOMER
WHERE ".$find." LIKE '%".$name."%' AND CUSTOMER.CUSTOMER_NUM = ORDERS.CUSTOMER_NUM";
} else
echo 'Match could not be found';
$result = mysql_query($query, $db);
$num_results = mysql_num_rows($result);
echo "<p>Number of results found: ".$num_results."</p>";
if ($find == a) {
for ($i=0; $i < $num_results; $i++) {
$row = mysql_fetch_assoc($result);
echo "<p>".($i+1).". Name: ";
echo $name;
echo "<br />Balance: ";
echo $row['BALANCE'];
echo "<br />Credit Limit: ";
echo $row['CREDIT_LIMIT'];
echo "</p>";
}
} else {
for ($i=0; $i < $num_results; $i++) {
$row = mysql_fetch_assoc($result);
echo "<p>".($i+1).". Name: ";
echo $name;
echo "<br />Orders: ";
echo $row['ORDER_NUM'];
echo "</p>";
}
}
mysql_free_result($result);
mysql_close($db);
?>