Page 1 of 1

search mysql table using php

Posted: Mon Mar 09, 2009 3:22 pm
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

Re: search mysql table using php

Posted: Mon Mar 09, 2009 3:32 pm
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".