Attila Posted July 19, 2008 Share Posted July 19, 2008 Hello I am trying to have someone enter somthing into a text block and submit it and have the results found in the database be shown. I am not sure what I am doing wrong here. You can see my site at: http://thaczero.com/search.php My coding is like this: <? $top_form = "<form method=\"post\" action=\"$_SERVER[php_SELF]\"> <table border=\"2\" cellpadding=\"2\" cellspacing=\"2\" bordercolor=\"#333333\" bgcolor=\"#CCCCCC\"> <tr align=\"center\" valign=\"middle\"> <td colspan=\"1\">"; $bottom_form = "</td> </tr> <tr> <td>Enter your search word, name, or phrase</td> <td><input type=\"text\" value=\"$_POST[search]\"></td> </tr> <tr align=\"center\" valign=\"middle\"> <td colspan=\"2\"> <input type=\"hidden\" name=\"op\" value=\"ds\"> <input type=\"submit\" name=\"Submit\" value=\"Search\"></td> </tr> </table> </form>"; if ($_POST[op] != "ds") { echo "In the if"; echo "$top_form"."$bottom_form"; } else { echo "in the else"; echo "$_POST[search]"; $item = $_POST[search]; echo "$item"; $sql = 'SELECT * FROM `ddoitems` WHERE `ItemDescription` LIKE "$item"'; database_connect(); $result = mysql_query($sql) or die(mysql_error()); echo "$top_form"."$bottom_form"; while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td><div align="center" class="style1">'.$row['ItemName'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['ItemDescription'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['Type'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['QuestName'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['lvl'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['Notes'].'</div></td>'; echo '</tr>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115621-_post-help/ Share on other sites More sharing options...
Goldeneye Posted July 19, 2008 Share Posted July 19, 2008 Try putting your $item variable inside %'s like so: <?php $sql = 'SELECT * FROM `ddoitems` WHERE `ItemDescription` LIKE "%$item%"'; ?> Also, This isn't necessary but I recommend putting quotes around your $_POST, $_GET, etc. variables. Example <?php $item = $_POST['search']; instead of $item = $_POST[search]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/115621-_post-help/#findComment-594362 Share on other sites More sharing options...
ignace Posted July 19, 2008 Share Posted July 19, 2008 I made some changes to your code @Goldeneye it is necessary imagine a constant named search having a value foobar, would take a long time to debug <? $top_form = "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\"> <table border=\"2\" cellpadding=\"2\" cellspacing=\"2\" bordercolor=\"#333333\" bgcolor=\"#CCCCCC\"> <tr align=\"center\" valign=\"middle\"> <td colspan=\"1\">"; $bottom_form = "</td> </tr> <tr> <td>Enter your search word, name, or phrase</td> <td><input type=\"text\" value=\"{$_POST['search']}\"></td> </tr> <tr align=\"center\" valign=\"middle\"> <td colspan=\"2\"> <input type=\"hidden\" name=\"op\" value=\"ds\"> <input type=\"submit\" name=\"Submit\" value=\"Search\"></td> </tr> </table> </form>"; if ($_POST['op'] != "ds") { echo "In the if"; echo "$top_form"."$bottom_form"; } else { echo "in the else"; echo "$_POST['search']"; $item = $_POST['search']; echo "$item"; $sql = 'SELECT * FROM `ddoitems` WHERE `ItemDescription` LIKE "%$item%"'; database_connect(); $result = mysql_query($sql/*, $dbconnection check php.net for the right syntax */) or die(mysql_error()); echo "$top_form"."$bottom_form"; while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td><div align="center" class="style1">'.$row['ItemName'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['ItemDescription'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['Type'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['QuestName'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['lvl'].'</div></td>'; echo '<td><div align="center" class="style1">'.$row['Notes'].'</div></td>'; echo '</tr>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115621-_post-help/#findComment-594363 Share on other sites More sharing options...
Attila Posted July 19, 2008 Author Share Posted July 19, 2008 That helped a lot but it does not apear to be getting what I type into the text block? So what is wrong with that portion of the code. Do I need the page to reload to post that into the $_POST['search']; Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/115621-_post-help/#findComment-594404 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.