Page 1 of 1

Help in this Search Query

Posted: Wed Aug 25, 2010 8:47 pm
by selvaganesh87
Hi PHP experts am entered into PHP my knowledge is up-to basic database connectivity. i studied search query which is running successfully but the output is not what i expected.
I get the string from the search box and searched with related to query from the database. My error is while search for specific string in search box, am not getting result for a specific string in search box, instead am getting the entire database values. Please help me out how to get search result for specific string in search box. Thanks

This is front end coding

<HTML>
<HEAD>
<TITLE>SHOP SEARCH</TITLE>
</HEAD>
<BODY>
<H2>Search For a Shop<H2>
<BR>
<FORM ACTION="search.php" METHOD="POST">
Enter the name of the product you are seeking
<BR>
<INPUT NAME="product" TYPE=TEXT>
<BR>
<INPUT TYPE=SUBMIT VALUE="search">
</FORM>
</BODY>
</HTML>

This is PHP Coding


<HTML>
<HEAD>
<TITLE>FANCY PRODUCTS</TITLE>
<BODY>
<H2>LIST OF FANCY PRODUCTS</H2>
<?
$db = mysql_connect("localhost");
mysql_select_db("stores", $db);
$query = "select fancystore.product, fancystore.quantity, fancystore.price from fancystore WHERE product LIKE '%".$product."%'";
$result = mysql_query($query);
while ($output = mysql_fetch_assoc($result))
{
while (list($sproduct, $sprice) = each($output))
{
echo $sproduct." : " .$sprice. "<BR>";
}
}
?>
</BODY>
</HTML>

Re: Help in this Search Query

Posted: Thu Aug 26, 2010 12:56 am
by atsa1
i think you have a typo in search.php should be like this:


<?
$product = $_POST['product'];
$db = mysql_connect("localhost");
mysql_select_db("stores", $db);
$query = ("select fancystore.product, fancystore.quantity, fancystore.price from fancystore WHERE product LIKE '%$product%' ");
$result = mysql_query($query);
while ($output = mysql_fetch_assoc($result))
{
while (list($sproduct, $sprice) = each($output))
{
echo $sproduct." : " .$sprice. "<BR>";
}
}
?>

let me know if it worked.

Re: Help in this Search Query

Posted: Fri Aug 27, 2010 9:28 pm
by selvaganesh87
Hey thank you very much ya. This code is working perfectly. Really i were confusing :banghead: for the whole day, now i got clear. Thank you very much