What do you want to do with the page?
if you know, you can get it to do it, then load the html after the process and move from there. The time for you queries won't be that long, so process your code, then the html and redirect to new page.
Here's the flow:
Start of page
process database queries
end of process queries
start of html
end of html
end of page
I use this model all the time to add things to the database, becasue it's simpler and easier than creating one page to do everything.
Here's one of mine:
<?php
// Start the session
session_start();
// Include the settings file and the auth script
// as this is a private page
include('../r/mysqlsettings.php');
include('../r/auth.php');
// include some error stuff, for when something goes wrong
$top = "<link href=\"admin.css\" rel=\"stylesheet\" type=\"text/css\"><meta http-equiv=\"refresh\" content=\"2;URL=javascript:history.back( )\"><br><br><br><br><br><br><br><br>
<div align=\"center\"><table width=60% border=0 cellpadding=3 cellspacing=1 class=\"blkbdr\">
<tbody>
<tr>
<td class=bmtext height=13><b><font size=2> You seem to have missed something out.</font></b></td>
</tr>
<tr>
<td height=29 bgcolor=white class=mtext>";
$bottom = " You should be returned to the previous page soon.
If not, please <a href=\"javascript:history.back( )\">click
here.</a></font></td>
</tr>
</tbody>
</table></div>";
//get input
$oils_id = $_POST['oils_id'];
$oils_name = $_POST['oils_name'];
$oils_description = $_POST['oils_description'];
/*
Make sure the input isn't odd, by removing
the slashes and code elements.
Also change the carrage returns into new lines
*/
// Strip HTML Tags
$oils_name = strip_tags($oils_name);
$oils_description = strip_tags($oils_description);
// Slashes
$oils_name = addslashes($oils_name);
$oils_description = addslashes($oils_description);
// nl2br
$oils_name = nl2br($oils_name);
$oils_description = nl2br($oils_description);
//Checks
if (!$oils_name)
{
echo $top;
echo "Please enter a title for this oil.";
echo $bottom;
exit;
}
if (!$oils_description)
{
echo $top;
echo "Please enter a description for this oil.";
echo $bottom;
exit;
}
// store that data
if ($oils_id)
{
// If it's an update, er, well, update.
$query = "UPDATE oils SET oils_name='$oils_name', oils_description='$oils_description' WHERE oils_id='$oils_id'";
}
else
{
// Add the information to the database
$query = "INSERT INTO oils (oils_name, oils_description)
VALUES ('$oils_name', '$oils_description')";
}
$result = mysql_query($query)
or die('MySQL error: '.mysql_error().'<br>Query: '.$query);
if ($result)
echo mysql_affected_rows(). " Oil Added to the Database.";
//html bit coming up - BAM!
?>
<html>
<head>
<title>Administration</title>
<link href="admin.css" rel="stylesheet" type="text/css">
<meta http-equiv="refresh" content="2;URL=oils_main.php">
</head>
<body>
<div class="centred">
<table class="blkbdr">
<tbody>
<tr>
<td class=bmtext> The Oil has been added to the database. </td>
</tr>
<tr>
<td class="mtext" > You should be returned to the
Oils Page soon. <br>
If not, please <a href="oils_main.php">click
here.</a> </td>
</tr>
</tbody>
</table></div>
</body>
</html>
Have a great day.
Hope this helps...
🙂