Jump to content

Search form errors (code included)


NextGenForum.net

Recommended Posts

The code below is a search form, that i have found on the web, the bolded lines are producing errors,

 

www.selectgreen.co.uk/search.php Search for company.

 

Any help, im hoping its ok apart from those problems

 

Thanks

<?
//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", "user", "password") or die(mysql_error());
mysql_select_db("databse") 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 property WHERE upper($field) LIKE'%$find%'");

//And we display the results
<b>while($result = mysql_fetch_array( $data ))</b>
{
echo $result['fname'];
echo " ";
echo $result['lname'];
echo "<br>";
echo $result['info'];
echo "<br>";
echo "<br>";
}

//This counts the number or results - and if there wasn't any it gives them a little message explaining that
<b>$anymatches=mysql_num_rows($data);</b>
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;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/76567-search-form-errors-code-included/
Share on other sites

You need to search by using the link searcg company

 

and the lines are bolded in this thread

 

Thankjs

I don't need to search by anything -- YOU need to post the error.  And you can't bold inside a code block (which I changed to make it more readable).  Besides, you put mysql functions in bold -- it's because whatever you're doing isn't a valid query.

<code>Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/nextgen/public_html/search.php on line 236

 

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

Sorry, but we can not find an entry to match your query</code>

 

These are the erroes thats i get after searching i hope thats what you need

 

Thanks

 

Also what do you put to get code boxes on the forums

<code>Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/nextgen/public_html/search.php on line 236

 

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

Sorry, but we can not find an entry to match your query</code>

 

These are the erroes thats i get after searching i hope thats what you need

 

Thanks

 

Also what do you put to get code boxes on the forums

 

[ code ] and [ / code ] -- without the spaces

 

Very good -- now, what's the mysql statement?  And please don't post the php line... I want to see an SQL statement.

 

WAIT -- you're missing a space after LIKE.

 

BUT STILL -- don't post about mysql errors without posting a mysql statment!  This is very clearly stated in the forum guidline.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.