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.

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>';
    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.