Code worked before, now (same code!) returning error

I’m a total noob to PHP, but I’m pretty sure this should be functional.

Here is the code. The code that was working, mind you, earlier this afternoon.

$entity=$HTTP_GET_VARS[‘entity’]; // from index.html
$uput=$HTTP_GET_VARS[‘uput’]; // from index.html
$uput= trim($uput);

	if (!$uput || !$entity)
	{echo 'You did not enter any text. Please go back and enter a first line, or % to retrieve all results.';

	$entity = addslashes($entity);
	$uput = addslashes($uput);
	$uput = str_replace(" ", "%", $uput);
	$uput = str_replace("-", "%", $uput);

	$db = mysql_connect('localhost', 'xxxxx', xxxx');

	if (!$db)
		echo 'Error: could not connect to database. Please try again.';


	$query = "select poem.poemid as id, fline, year, book, verse from poem
		join pobib on poem.poemid=pobib.poemid
		join bibal on pobib.bibalid=bibal.bibalid
		where ".$entity." like '%".$uput."%'";

	$result = mysql_query($query);
	$num_results = mysql_num_rows($result);

Error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/ on line 62

Line 62 here is [php]$num_results = mysql_num_rows($result);[/php], so I’m assuming a problem is being detected in the query. I can’t see the problem. The only thing I know is that poem.poemid has given the script problems in the past, but only in generating output. Solved this with the “as id”.

Anybody else see my error, or have any ideas about what might be causing the problem if not the code itself?


Before this line #62, for debugging purpose, try to add this:
[php]echo mysql_error();[/php]

This will show you detail about problem in your SQL query.

P.S. That missing apostrophe (’) in the connection to the host isn’t actually missing in the code. I accidentally deleted that when posting here. Sorry. My error isn’t in connecting to the db. There’s something wrong with the query… I think.

Thank you! That did identify the error more specifically.

“Unknown column ‘ufline’ in ‘where clause’”

However, I don’t know how to fix this. This is one of the possible values for $entity, which is coming from a drop-down menu in a search form in index.html. Do these values need to match the values in my SQL table?

Nevermind. That was the problem. My menu values needed to match the database column values. Don’t know how I missed that. Thanks so much for your help!

Sponsor our Newsletter | Privacy Policy | Terms of Service