Jump to content

php search bar for my site


andrew_biggart

Recommended Posts

hi can anyone help me out with making a php search bar for my site, i have one at the moment and the code is as follows.

 

<?php

include("config.php");

$_POST['search']=addslashes ($search);

// Retrieve data from database

$sql="SELECT * FROM $tbl_name WHERE item_name LIKE '%$search%' ";

$result=mysql_query($sql);

 

// Start looping rows in mysql database.

while($rows=mysql_fetch_array($result)){

?>

 

<table class= "select_main"width="400" border="0" cellspacing="0" cellpadding="4">

<tr>

<td style="width: 40px"><? echo "<img src='images/". $rows['item_image'] . "' style='width:60px; height:80px;' />";?></td>

<td style="width: 313px"><? echo $rows['item_name']; ?></td>

<td style="width: 57px"><? echo $rows['item_starting_price']; ?></td>

<td><? echo $rows['end_date']; ?></td>

<tr/>

</table>

 

<?

// close while loop

}

 

// close connection

mysql_close();

this brings up every product in the database due to the wild cards i think. What am i doing wrong any 1????????

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/106384-php-search-bar-for-my-site/
Share on other sites

Why are you resetting a POST value?:

 

    $_POST['search']=addslashes ($search);

 

Should that be:

 

$search = addslashes($_POST['search']);

 

?

 

ok ive sorted this but it is still bringing up every product in the database ???????

Can you give an example of a search and the entire result list?  Is the search term comparable to all of the results?

 

well basically i am designing an online clothing auction for an assignment. Say i search for hat or coat or what ever all of the products i have stored in the database are shown !!!

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.