phpnewbie34 Posted May 6, 2013 Share Posted May 6, 2013 Hello friends. I am have a search bar that displays results from my DB How do I refresh the page (e.i, index.php) and add the info to a search bar when the user clicks SUBMIT note: I do not want another page - Just one, THANKS Quote Link to comment Share on other sites More sharing options...
wright67uk Posted May 6, 2013 Share Posted May 6, 2013 You can submit the form to the current page. action="<?php echo $_SERVER['PHP_SELF']; ?>" Any form action will reload a page Quote Link to comment Share on other sites More sharing options...
RonnieCosta50 Posted May 7, 2013 Share Posted May 7, 2013 I think this is what you want. You want the user to search for something in the database and have it displayed. I'm assuming it will display more than one result so you will need an html table. <body> <form name="search" method="post"> // "search" is the name of the button. <!--here's a textbox for input.--> <input name="wsTextbox1" tabindex="0" style="width: 150px; background-color: #BBAE85;" maxlength="15" required="required" autofocus="autofocus" placeholder="Enter Search Criteria" /> <!--Here's a submit button--> <input type="submit" name="btnSubmit" value="Submit" class="button" style="width: 80px"/> <table> <?php // SEARCHES FOR DATA IN YOUR DATABASE $search = $_POST['search']; // The variable name $search is equal to the click of the search button. if ($search) // If the search button is clicked, { // since you want everything on one page, you will have to add code here for your database connection. // I'm just going to use multiple pages to demonstrate. include 'dbConnect.php'; // Connects to database. include 'dbTableName.php'; // Gets the database table name. include 'dbTableColumns.php'; // Gets the database table column names. // This is a sample sql statement. Modify it to the website criteria. $sqlSELECT = "SELECT * FROM $dbTableName WHERE $dbColumnName1 LIKE '%$wsTextbox1%' ORDER BY $dbColumn2 DESC, $dbColumn2 DESC LIMIT 10"; $qrySELECT=mysql_query("$sqlSELECT"); } // DISPLAYS DATA FROM DATABASE INTO HTML TABLE while($rows=mysql_fetch_array($qrySELECT)) { echo'<tr>'; echo'<td style="width: 100px">'.$rows[$dbColumnName1].'</td>'; //$dbColumnName is the name is the column in your database. echo'<td style="width: 100px">'.$rows[$dbColumnName2].'</td>'; echo'</tr>'; } </table></form></body> ?> This is how you refresh a page. But you don't need to do this because when you press the submit button it will reload the page automatically. But here's the code anyway for reference. echo "<meta http-equiv=\"refresh\" content=\"0;URL=../editHere.php\">"; Change the part that says ../editHere.php to match your directory and file name. Quote Link to comment Share on other sites More sharing options...
RonnieCosta50 Posted May 7, 2013 Share Posted May 7, 2013 I think this is what you want. You want the user to search for something in the database and have it displayed. I'm assuming it will display more than one result so you will need an html table. <body> <form name="search" method="post"> // "search" is the name of the button. <!--here's a textbox for input.--> <input name="wsTextbox1" tabindex="0" style="width: 150px; background-color: #BBAE85;" maxlength="15" required="required" autofocus="autofocus" placeholder="Enter Search Criteria" /> <!--Here's a submit button--> <input type="submit" name="btnSubmit" value="Submit" class="button" style="width: 80px"/> <table> <?php // SEARCHES FOR DATA IN YOUR DATABASE $search = $_POST['search']; // The variable name $search is equal to the click of the search button. if ($search) // If the search button is clicked, { // since you want everything on one page, you will have to add code here for your database connection. // I'm just going to use multiple pages to demonstrate. include 'dbConnect.php'; // Connects to database. include 'dbTableName.php'; // Gets the database table name. include 'dbTableColumns.php'; // Gets the database table column names. // This is a sample sql statement. Modify it to the website criteria. $sqlSELECT = "SELECT * FROM $dbTableName WHERE $dbColumnName1 LIKE '%$wsTextbox1%' ORDER BY $dbColumn2 DESC, $dbColumn2 DESC LIMIT 10"; $qrySELECT=mysql_query("$sqlSELECT"); } // DISPLAYS DATA FROM DATABASE INTO HTML TABLE while($rows=mysql_fetch_array($qrySELECT)) { echo'<tr>'; echo'<td style="width: 100px">'.$rows[$dbColumnName1].'</td>'; //$dbColumnName is the name is the column in your database. echo'<td style="width: 100px">'.$rows[$dbColumnName2].'</td>'; echo'</tr>'; } </table></form></body> ?> This is how you refresh a page. But you don't need to do this because when you press the submit button it will reload the page automatically. But here's the code anyway for reference. echo "<meta http-equiv=\"refresh\" content=\"0;URL=../editHere.php\">"; Change the part that says ../editHere.php to match your directory and file name. I guess if you don't want to use a database table, you could just echo. Replace this part... // DISPLAYS DATA FROM DATABASE INTO HTML TABLE while($rows=mysql_fetch_array($qrySELECT)) { echo'<tr>'; echo'<td style="width: 100px">'.$rows[$dbColumnName1].'</td>'; //$dbColumnName is the name is the column in your database. echo'<td style="width: 100px">'.$rows[$dbColumnName2].'</td>'; echo'</tr>'; } With this... // DISPLAYS DATA FROM DATABASE WITH ECHO while($rows=mysql_fetch_array($qrySELECT)) { echo'$rows[$dbColumnName1] </br>'; //$dbColumnName is the name is the column in your database. echo'$rows[$dbColumnName2] </br>'; } Quote Link to comment 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.