Dyvn Posted December 18, 2008 Share Posted December 18, 2008 Here's my search field: <form name="search" method="post" action="<?=$PHP_SELF?>"> <Select NAME="field" id="field"> <Option VALUE="title">Title</option> <Option VALUE="synopsis">Synopsis</option> <Option VALUE="author">Author</option> <Option VALUE="category">Category</option> </Select> <input type="text" id="find" name="find" /> <input type="hidden" id="searching" name="searching" value="yes" /> <input type="submit" id="search" name="search" value="Go" /> </form> and here's my PHP/SQL to get the data: <? if ($searching =="yes") { if ($find == "") { echo "<table width='90%'><tr><td align='left'><font color='white' face='arial' size='5'>No term entered, please try again.</font></td></tr></table>"; exit; } // Otherwise we connect to our Database mysql_connect("edit","edit","edit") or die(mysql_error()); mysql_select_db("edit") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM tutsearch WHERE upper($field) LIKE'%$find%'"); echo "<table width='90%'>"; echo "<tr>"; echo "<td width='20%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'><b>Title</b></font>"; echo "</td>"; echo "<td width='55%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'><b>Synopsis</b></font>"; echo "</td>"; echo "<td width='10%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'><b>Category</b></font>"; echo "</td>"; echo "<td width='15%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'><b>Author</b></font>"; echo "</td>"; echo "</tr>"; // Display results while($result = mysql_fetch_array( $data )) { echo "<tr>"; echo "<td width='20%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'>" .$result['Title']. "</font>"; echo "</td>"; echo "<td width='55%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'>" .$result['Synopsis']. "</font>"; echo "</td>"; echo "<td width='10%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'>" .$result['Category']. "</font>"; echo "</td>"; echo "<td width='15%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'>" .$result['Author']. "</font>"; echo "</td>"; echo "</tr>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "<tr>"; echo "<td width='15%' bgcolor='#111111'>"; echo "<font color='white' face='arial' size='3'>No matches were found for your search.</font>"; echo "</td>"; echo "</tr>"; } echo "</table>"; } ?> It I can't find out what's wrong! Please help! Quote Link to comment https://forums.phpfreaks.com/topic/137596-simple-database-search-not-working-help-please/ Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 Unless you have register globals set to ON (which you probably don't), posted data is stored in $_POST['varname'] or $_GET['varname'] (depending on your post method), not $varname. Quote Link to comment https://forums.phpfreaks.com/topic/137596-simple-database-search-not-working-help-please/#findComment-719194 Share on other sites More sharing options...
Dyvn Posted December 18, 2008 Author Share Posted December 18, 2008 Thanks so much!! You're heroic! Quote Link to comment https://forums.phpfreaks.com/topic/137596-simple-database-search-not-working-help-please/#findComment-719199 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 I just glimpsed over your code and saw: </pre> <form name="search" method="post" action="<?=%24PHP_SELF?>">< which again, is a global variable issue, and needs to be: (and don't use short tags to start PHP "" use "<?php". </pre> <form name="search" method="post" action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>">< Quote Link to comment https://forums.phpfreaks.com/topic/137596-simple-database-search-not-working-help-please/#findComment-719202 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 I just glimpsed over your code and saw: <form name="search" method="post" action="<?=$PHP_SELF?>"> which again, is a global variable issue, and needs to be: (and don't use short tags to start PHP "<?" use "<?php". <form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> re: $PHP_SELF Happy side effect to continued use of $PHP_SELF is that it results in echoing out action='' which under these circumstances, produces the same effect as using $_SERVER['PHP_SELF']. Now, if he were wanting to reference the current script in another script...that would bea different story. re: using short tags. <?= $variable ?> This is actually shorthand for doing <?php echo $variable; ?>. It is not the same as doing <? echo $variable; ?> (using short tags). Although to be fair, <?= .. ?> is a setting in php.ini that can be enabled/disabled, thus putting it in the same boat as short tags, as far as possible server incompatibility. Quote Link to comment https://forums.phpfreaks.com/topic/137596-simple-database-search-not-working-help-please/#findComment-719219 Share on other sites More sharing options...
Maq Posted December 18, 2008 Share Posted December 18, 2008 Thanks for the info CV Quote Link to comment https://forums.phpfreaks.com/topic/137596-simple-database-search-not-working-help-please/#findComment-719222 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.