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);
?>

This error means that the query returned 0 rows. This can either be due to the fact that there isn't any rows OR that the query its self is incorrect and not pulling the desired results.

To troubleshoot the query it's self I would take the query and put it in php myadmin obviously fill in the areas that would usually be filled with PHP variables.

Then run the query, if it still returns 0 then it may be that you have an error in the PHP variables or processes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.