Jump to content

How to refresh page using Submit and PHP


phpnewbie34

Recommended Posts

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.

Link to comment
Share on other sites

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>';
    }
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.