Page 1 of 1

[SOLVED] Redirect problems after POST

Posted: Sun Feb 22, 2009 5:58 am
by DSpeed
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:

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");
            }
 
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:

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");
        }
    }
 
If this is a problem with header() can somebody please explain it so that I may understand, or suggest another alternative to the redirect?

Re: Redirect problems after POST

Posted: Sun Feb 22, 2009 6:40 am
by requinix

Code: Select all

header("Location : profile.php");
You've got one too many spaces in there. Yes, it matters.

Re: Redirect problems after POST

Posted: Sun Feb 22, 2009 7:02 am
by DSpeed
tasairis wrote:

Code: Select all

header("Location : profile.php");
You've got one too many spaces in there. Yes, it matters.
A part of my soul just died :banghead:
Thank you very much for the help, I was expecting some strange logic error, and not a simple syntax error. Perhaps I was staring at it for too long.

Anyway, I appreciate it.