search mysql table using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vin_akleh
Forum Commoner
Posts: 53
Joined: Sat Feb 14, 2009 10:26 am

search mysql table using php

Post by vin_akleh »

there is something wrong with this code what ever i search for i gives me
no result found

Code: Select all

 <form name="form" action="" method="get">
<input type="hidden" name="action" value="srch"/>
<input type="text" name="search" />
<input type="submit" name="Submit" value="Search" />
</form>
<?php
$count=0;
$i=0;
if ($_REQUEST["action"]=='srch'){
$fechdbase=mysql_query("select count(*) from Links
where
srch='".$_REQUEST["name"]."' || '".$_REQUEST["url"]."'");
$result=mysql_fetch_array($fechdbase);
if ($result[0]!=0){
while ($result[$i]!=count($result)){
echo '<td>  <a href="http://'.$result["url"].'">
<img src="http://'.$result['picture'].'" width=150 height= 200></a></td>';
$count++;
if ($count==3){
echo '</tr><tr>';
$count=0;
}//end if
$i++;
}//end while
echo '</tr>';}
else{
echo 'no result found';}}
?>
need help
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: search mysql table using php

Post by Reviresco »

I see at least one problem:

Code: Select all

where
srch='".$_REQUEST["name"]."' || '".$_REQUEST["url"]."'");
There's nothing in the form called "name" or "url". You want to search for

Code: Select all

$_GET['search']
Also, the WHERE clause doesn't look like it's set up properly. And what fields are you looking in? Somehow I doubt it's called "srch".
Post Reply