Page 1 of 1

NEED SOME HELP PEOPS

Posted: Mon Mar 17, 2003 8:28 am
by vxp00u
Hello, i have created a db, and loaded a set of values into it via a text file! However the problem occurs when i try to extract data from the db via a keyword search from a html form. The result shud give a list of values that match the search key that is entered!

The error that i get is this:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /stud/ug/vxp00u/cgi-bin/viral/searchpage3result.cgi on line 33!

I would really appreciate it if some1 could point out where im goin wrong PLZ!

Code: Select all

<html>
<head><title>TERM SEARCH RESULTS</title></head>
<body>
<h1>SEARCH RESULTS</h1>

<?php
	trim($searchterm);
	if (!$searchtype || !$searchterm)
	&#123;
	echo "you have not entered search details, plz go bak and try again";
	exit;
	&#125;
	$searchtype = addslashes($searchtype);
	$searchterm = addslashes($searchterm);

	@ $db = mysql_connect("mysql.cs.nott.ac.uk", "username", "password");
	
	if (!$db)
	&#123;
	echo "error: could not connect to the database. please try again later.";
	exit;
	&#125;


	mysql_select_db("testtable");
	$query = "SELECT * FROM testtable WHERE '.$searchtype.' LIKE '%".$searchterm."%'";
	$result = mysql_query($query);
		
	$num_results=mysql_num_rows($result);

	echo "<p>Number of terms found: ".$num_results."</p>";

	for ($i=0; $i < $num_results; $i++)
	&#123;
	$row = mysql_fetch_array($result);
	echo "<p><strong>".($i+1).".letter:";
	echo htmlspecialchars( stripslashes($row&#1111;"letter"]));
	echo "</strong><br>term: ";
	echo htmlspecialchars( stripslashes($row&#1111;"term"]));
	echo "</strong><br>meaning: ";
	echo htmlspecialchars( stripslashes($row&#1111;"meaning"]));
	echo "</p>";
	&#125;
	?>
</body>
</html>
cheers VIRAL :cry:

Posted: Mon Mar 17, 2003 8:32 am
by twigletmac
It sounds like there is an error with your query, try changing:

Code: Select all

$result = mysql_query($query);
to

Code: Select all

$result = mysql_query($query) or die(mysql_error().'<p>'.$query.'</p>');
to see the error MySQL has generated about the SQL statement.

You may find this has some bearing on the problem:
viewtopic.php?t=511

Mac

Posted: Mon Mar 17, 2003 9:57 am
by vxp00u
cheers mate, that helped me weed the error out in order for it to run, but i still cant get the search to work properly!

The form has a drop down selection menu with options, "letter", "term" and "meaning"! but when i enter a search letter, term or meaning, it says there are no results! BUT when i enter letter "a" in the feild and search it, the entire contents of the database is returned??

Any ideas?

Viral