...

View Full Version : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource



lsmamadele
08-16-2007, 12:28 AM
I am getting the following error messages in my search:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on line 113

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mamadele/public_html/BESTPLAYS/search.php on line 127

My code is below. Any help would be much appreciated.

****************************************************************

<?
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("DBnam") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");

//And we display the results
while($result = mysql_fetch_array($data))
{
echo $result['ID'];
echo "<br>";
echo $result['Play'];
echo "<br>";
echo $result['Volume'];
echo "<br>";
echo $result['Opened'];
echo "<br>";
echo $result['Performances'];
echo "<br>";
}

//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>

Nightfire
08-16-2007, 12:33 AM
Looks like your query failed to me.

Also, please use the
tags next time you post php code to make it easier to read

Inigoesdr
08-16-2007, 12:34 AM
Your query is failing.. first guess would be because $field isn't set. Add or die(mysql_error()); to it to see the error.

lsmamadele
08-16-2007, 12:47 AM
thanks for the quick response.

where should I put the : or die(mysql_error()); ???

lsmamadele
08-16-2007, 12:49 AM
and I think the $field is set in the form:

<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="Play">Play</option>
<Option VALUE="Volume">Volume</option>
<Option VALUE="Opened">Opened</option>
<Option VALUE="Performances">Performances</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>

Nightfire
08-16-2007, 12:54 AM
$data = mysql_query("SELECT * FROM users WHERE upper('".$_POST['field']."') LIKE '%$find%' ") or die("Error: ".mysql_error());

lsmamadele
08-16-2007, 01:02 AM
Thanks so much for your help!!!

It works!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum