monger Posted January 29, 2011 Share Posted January 29, 2011 //here is the code. For some reason it searches the first time, but the second search loads everything. testing at: mnmotorsports.com // searcha.php <?php require("head.php");?> <table width="800" border="1"><tr><td width="550"></td><td> <form method="post" action="searcha.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="Search"> </form> </td></tr> <tr><td height ="300"> <?php echo "searching"; // connect to host require("connect.php"); // retrieve data $name = $_POST['name']; echo " any card name matching: <b>'".$name."'</b>"; $query = "SELECT * FROM ".$tname." WHERE name LIKE '%".$name."%'"; $result = mysql_query($query) or die(mysql_error()); $SearchCntr=0; while($row = mysql_fetch_array($result)){ $SearchCntr++; echo "<table border='1' width='500'>"; echo "<tr><td>".$row['edition']." | <a href='#'>".$row['name']."</a> | ".$row['manacost']." | ".$row['price']."</td></tr>"; echo "</table>"; } echo $SearchCntr." SEARCH RESULTS</body></html>"; ?> </td><td></td> </tr> </table> <?php require("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/ Share on other sites More sharing options...
monger Posted January 29, 2011 Author Share Posted January 29, 2011 ------ index.php ------- <?php require("head.php");?> <table width="800" border="1"><tr><td width="550"></td><td> <form method="post" action="<?PHP POST_SELF; ?>" id="searchcards"> <input type="text" name="name"> <input type="submit" name="submit" value="search"> </form> </td></tr> <tr><td height ="300"><?php require("search.php"); ?></td><td></td> </tr> </table> <?php require("footer.php"); ?> -------- search.php ---------- <?php if ($_POST['submit']=="search"){ // connect to host require("connect.php"); // retrieve data $name = $_POST['name']; echo "Searching any card name matching: <b>'".$name."'</b>"; $query = "SELECT * FROM ".$tname." WHERE name LIKE '%".$name."%'"; $result = mysql_query($query) or die(mysql_error()); $SearchCntr=0; while($row = mysql_fetch_array($result)){ $SearchCntr++; echo "<table border='1' width='500'>"; echo "<tr><td>".$row['edition']." | <a href='#'>".$row['name']."</a> | ".$row['manacost']." | ".$row['price']."</td></tr>"; echo "</table>"; } echo $SearchCntr." SEARCH RESULTS</body></html>"; }else{ echo "Search failed"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/#findComment-1167118 Share on other sites More sharing options...
monger Posted January 29, 2011 Author Share Posted January 29, 2011 for some reason, post doesnt run correctly the second time around.. Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/#findComment-1167120 Share on other sites More sharing options...
monger Posted January 30, 2011 Author Share Posted January 30, 2011 for some reason, post doesnt run correctly the second time around.. is post made to run only once? help!? Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/#findComment-1167153 Share on other sites More sharing options...
monger Posted January 30, 2011 Author Share Posted January 30, 2011 how come my post method text search box works only once? -testing at mnmotorsports.com/searchtest2.php --------------- simple version ------------------ <form method="post" action="<?PHP POST_SELF; ?>" id="searchcards"> <input type="text" name="name"> <input type="submit" name="submit" value="search"> </form> <?php // connect to host require("connect.php"); // retrieve data $name = $_POST['name']; echo "Names matching: <b>'".$name."'</b>"; $query = "SELECT * FROM ".$tablename." WHERE name LIKE '%$name%' ORDER BY name ASC"; $result = mysql_query($query) or die(mysql_error()); $SearchCntr=0; while($row = mysql_fetch_array($result)){ $SearchCntr++; echo "<table border='1'><tr><td><a href='#'>".$row['name']."</td></tr></table>"; } echo $SearchCntr." SEARCH RESULTS"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/#findComment-1167166 Share on other sites More sharing options...
jcbones Posted January 30, 2011 Share Posted January 30, 2011 Well, how many times do you want it to search? Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/#findComment-1167171 Share on other sites More sharing options...
BlueSkyIS Posted January 30, 2011 Share Posted January 30, 2011 what is this? <?PHP POST_SELF; ?> I doubt it's doing anything, but it's probably not helping. Just delete it. Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/#findComment-1167174 Share on other sites More sharing options...
monger Posted January 30, 2011 Author Share Posted January 30, 2011 yeah, i just started scripting php about 4 days ago. I don't normally script in php. The idea is to create an input text box. (that looks for %letters% in one row of info from the database) It works, but not seamlessly. Somewhere there seems to be an error in the script and it works only once. It's supposed to work over and over. Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/#findComment-1167180 Share on other sites More sharing options...
jcbones Posted January 30, 2011 Share Posted January 30, 2011 PHP scripts run ONCE, before the server sends the browser the output generated by the script. If you want it to search over and over, you will need to couple it with some javascript to refresh the page on interval. Quote Link to comment https://forums.phpfreaks.com/topic/226085-how-come-my-post-method-search-box-works-only-once/#findComment-1167206 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.