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
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?

 

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

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.