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 Link to comment https://forums.phpfreaks.com/topic/106384-php-search-bar-for-my-site/ 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']); ? Link to comment https://forums.phpfreaks.com/topic/106384-php-search-bar-for-my-site/#findComment-545376 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 ??????? Link to comment https://forums.phpfreaks.com/topic/106384-php-search-bar-for-my-site/#findComment-545917 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? Link to comment https://forums.phpfreaks.com/topic/106384-php-search-bar-for-my-site/#findComment-545952 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 !!! Link to comment https://forums.phpfreaks.com/topic/106384-php-search-bar-for-my-site/#findComment-546923 Share on other sites More sharing options...
947740 Posted May 22, 2008 Share Posted May 22, 2008 Can you show your new code? Link to comment https://forums.phpfreaks.com/topic/106384-php-search-bar-for-my-site/#findComment-547406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.