Jump to content

refresh current page after submit?


Imaulle

Recommended Posts

Hello,

 

I'm having trouble figured out how to do this... Basically I want update.php to run after the user hits the 'update' button, and after update.php runs (which will take about 60 seconds) I want the index.php to reload. How can this be done?

 

 

thanks!

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
  <title>Server List</title>
</head>
<body>
<?php
$mlink = @mysql_connect("localhost","user","pass");
mysql_select_db("dbname", $mlink);
$result = mysql_query("SELECT * FROM ServerList");
while($row = mysql_fetch_array($result)){
echo $row['HostName']. " - ". $row['UsedSlots']. " / ". $row['MaxSlots'];
echo "<br />";
}
?>
<br/>
<br/>
<form action="update.php" method="post">
<button type="submit">update</button>
</form>
</center>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/
Share on other sites

what's the scenario here? As you aren't posting asynchronously, and the form action is aimed at update.php the user will have to wait until update.php has finished being run on the server before the page response is sent and they can navigate back to the index page at which point the page will be refreshed anyway. Not sure what the problem your having is? Are you using ajax or something which you haven't mentioned?

 

here is the update.php just so you can see what I'm doing

 

<?php
require_once('whm.php');
$mlink = @mysql_connect("localhost","user","pass");
mysql_select_db("dbname", $mlink);
$result = mysql_query("SELECT * FROM ServerList");
while($row = mysql_fetch_array($result)){
  $server = new Whm;
  $server->init($row['HostName'],$row['UserName'],$row['PassHash']);
  $NewUsedSlots = count($server->listaccts());
  mysql_query("UPDATE ServerList SET UsedSlots='$NewUsedSlots' WHERE HostName='{$row['HostName']}'",$mlink);
}
?>

Okay, I'm guessing that you just want to redirect your user to the index page after the update.php code has run, in that case just add:

 

header('Location: http://www.example.com/index.php');

 

after your code but before any html (or even whitespace) is added. Is that what you're looking for?

You might try testing to see if you are in CLI (command line) mode and only do the redirect if you are not:

 

if (php_sapi_name() != 'cli')
header('Location: http://www.example.com/index.php');

 

OR check for one of the $_SERVER array elements that are only present when running from the browser, such as

 

if (isset($_SERVER['DOCUMENT_ROOT']))
header('Location: http://www.example.com/index.php');

 

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.