[SOLVED] Redirect problems after POST
Posted: Sun Feb 22, 2009 5:58 am
Hi all,
I have recently started to write in PHP for my university course and am a little confused over an issue. I'm having problems using header("Location: mylink"); to redirect the users between pages.
Here is the relevant code:
The query is running fine, and the database is being updated, though the redirect is never executed. This is on an 'Edit Profile' page with textareas populated with information from the database, with the user able to update the textareas, then click on an Update button to update the database.
I am trying to automatically redirect the user from the EditProfile page, back to their original Profile page without an intermediate "You have updated your profile" dialog in between.
Sorry if this is a silly question, but I cannot see why header() doesn't execute in a POST environment.
Any help would be muchly appreciated and gratefully recieved.
Thanks,
DSpeed
EDIT:
Just to add, in a different page, I have been able to achieve this so am confused concerning why it will not execute now:
If this is a problem with header() can somebody please explain it so that I may understand, or suggest another alternative to the redirect?
I have recently started to write in PHP for my university course and am a little confused over an issue. I'm having problems using header("Location: mylink"); to redirect the users between pages.
Here is the relevant code:
Code: Select all
//Let the user update the information in the textboxes.
if(isset($_POST["update"]))
{
$updateQuery = //query here
$queryExec = mysql_query($updateQuery);
header("Location : profile.php");
}
I am trying to automatically redirect the user from the EditProfile page, back to their original Profile page without an intermediate "You have updated your profile" dialog in between.
Sorry if this is a silly question, but I cannot see why header() doesn't execute in a POST environment.
Any help would be muchly appreciated and gratefully recieved.
Thanks,
DSpeed
EDIT:
Just to add, in a different page, I have been able to achieve this so am confused concerning why it will not execute now:
Code: Select all
if(isset($_POST["submit"]))
{
$loginUserQuery = "SELECT * FROM users WHERE UserNick = '$_POST[username]' AND UserPass = '$_POST[password]'";
$queryExec = mysql_query($loginUserQuery);
$queryResult = mysql_fetch_object($queryExec);
if(!empty($queryResult))
{
//dump the query in to a new object, and register it as a global with the sessiojn
$UserObj = $queryResult;
$_SESSION['UserObj'] = $UserObj;
header('location: profile.php'); ///// <--- This works
}
else
{
echo("User not found");
}
}