andrew_biggart Posted May 19, 2008 Share Posted May 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
947740 Posted May 20, 2008 Share Posted May 20, 2008 Why are you resetting a POST value?: $_POST['search']=addslashes ($search); Should that be: $search = addslashes($_POST['search']); ? Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted May 20, 2008 Author Share Posted May 20, 2008 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 ??????? Quote Link to comment Share on other sites More sharing options...
947740 Posted May 20, 2008 Share Posted May 20, 2008 Can you give an example of a search and the entire result list? Is the search term comparable to all of the results? Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted May 21, 2008 Author Share Posted May 21, 2008 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 !!! Quote Link to comment Share on other sites More sharing options...
947740 Posted May 22, 2008 Share Posted May 22, 2008 Can you show your new code? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.