helpmeplease2 Posted September 1, 2007 Share Posted September 1, 2007 I am using this code which I found on about.com and I have changed it to my needs but it is not working. No results appear when a search is made. I do have a database with many rows of data. Now can someone head in me the right direction to making this work? <?php echo "<h3>Search</h3> <form name='search' method='post' action='$PHP_SELF'> Search for: <input type='text' name='find' /> in <Select NAME='field'> <Option VALUE='VTitle'>Videos</option> <Option VALUE='GTitle'>Games</option> </Select> <input type='hidden' name='searching' value='yes' /> <input type='submit' name='search' value='Search' /> </form>"; if ($searching =="yes") { echo "<h1>Search Results</h1><p>"; if ($find == "") { echo "<p>You forgot to enter a search term."; exit; } $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); echo "<table cellspacing='0' cellpadding='0' class='bordercolor' border='0' style='margin-top: 1px; vertical-align: top;' align='center'>"; $row = mysql_query("SELECT GTitle,VTitle,IFilename FROM videos WHERE upper($field) NOT LIKE '</a>' AND upper($field) LIKE '%$find%'"); while($result = mysql_fetch_array( $row )) { $game=$row['GTitle']; $video=$row['VTitle']; $image1=$row['IFilename']; if ($image1==""){ $image="images/favicon.gif"; }else{ $image=$row['IFilename']; } echo "<tr> <td class='windowbg2' width='150' align='center'><div class='windowbg2' style='width:150; align:center;'><img src='$image' border='0' height='75'></div></td> <td class='windowbg2' width='485' valign='center'> <a href='http://www.gameanyone.com?p=game&game=$game'>$game</a>:<br> <a href='http://www.gameanyone.com?p=video&game=$game&video=$video'>$video</a></td></tr>"; } echo "</table>"; $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } echo "<b>Searched For:</b> " .$find; } ?> Edit: To see the page go here: http://www.gameanyone.com/?p=thesearch Quote Link to comment https://forums.phpfreaks.com/topic/67574-search-not-working/ Share on other sites More sharing options...
recklessgeneral Posted September 4, 2007 Share Posted September 4, 2007 Hi, This looks like it is caused by register_globals being off for you but was probably on for the authors at about.com who wrote the original code. For info about register_globals and the headaches it causes to the unwary, see here: http://www.php.net/register_globals Now, how to fix it. The values are available to the PHP code in a couple of special arrays. All data posted from the form can be accessed through the $_POST array, passing in the field name as the key. Also, PHP_SELF can be accessed through a different pre-defined array $_SERVER. So, the action part of the form becomes action="{$_SERVER['PHP_SELF']}". Then, after the echo command, I'd extract each of the $_POST variables into its own local copy: $searching = $_POST['searching']; $find = $_POST['find']; $field = $_POST['field']; Cheers, Darren. Quote Link to comment https://forums.phpfreaks.com/topic/67574-search-not-working/#findComment-341150 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.