Imaulle Posted December 21, 2010 Share Posted December 21, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/ Share on other sites More sharing options...
topcat Posted December 21, 2010 Share Posted December 21, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/#findComment-1149724 Share on other sites More sharing options...
Imaulle Posted December 21, 2010 Author Share Posted December 21, 2010 Not using AJAX, I'd just like it so the user can simply hit the 'update' button and then wait for update.php to run, then refresh the index.php to view the changes that update.php made. I'm not sure if there is a better way to do it... Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/#findComment-1149726 Share on other sites More sharing options...
Imaulle Posted December 21, 2010 Author Share Posted December 21, 2010 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/#findComment-1149728 Share on other sites More sharing options...
topcat Posted December 21, 2010 Share Posted December 21, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/#findComment-1149740 Share on other sites More sharing options...
Imaulle Posted December 21, 2010 Author Share Posted December 21, 2010 I didn't want to modify the update.php because I have that to run twice a day via cron will adding that line interfere with that at all? Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/#findComment-1149763 Share on other sites More sharing options...
DavidAM Posted December 21, 2010 Share Posted December 21, 2010 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'); Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/#findComment-1149776 Share on other sites More sharing options...
Imaulle Posted December 21, 2010 Author Share Posted December 21, 2010 Hey thanks! I went with the 2nd option and it seems to be working :] on another unrelated note, can anyone tell me what program this is? thank you everyone! Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/#findComment-1149783 Share on other sites More sharing options...
topcat Posted December 21, 2010 Share Posted December 21, 2010 What a question! Looks like Aptana Studio to me. But there are a few that look similat such as Eclipse etc. Quote Link to comment https://forums.phpfreaks.com/topic/222260-refresh-current-page-after-submit/#findComment-1149793 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.