Nathan Riley
asked on
PHP Redirect at end of Page
I have a PHP page the goes and updates data in my MYSQL database after that code is complete I would like the page to redirect back to another page.
How do I do this? I found info on a header redirect, but don't want that, I don't want it to redirect to the next page until after my other code in the php page has executed.
How do I do this? I found info on a header redirect, but don't want that, I don't want it to redirect to the next page until after my other code in the php page has executed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Because PHP runs procedurally, you can run your SQL code (or anything else) and then call the redirect with the header function at the end. You can put some checks in place so that it only gets called if you want it to.
<?php
//do something here.
if ($success ) {
header('Location: http://www.yourdomain.com/nextpage.php');
} else {
//do something else...
}
The header function needs to be called before any output, so will only work if the other part of your script (the database bits) doesn't output anything to the browser.
<?php
//do something here.
if ($success ) {
header('Location: http://www.yourdomain.com/nextpage.php');
} else {
//do something else...
}
The header function needs to be called before any output, so will only work if the other part of your script (the database bits) doesn't output anything to the browser.
Oops. Bit late posting that one :)
ASKER
I was confused and since I saw the word header assumed it would just redirect right away rather than execute the rest of the database/php code.
Thanks!