[SOLVED] Redirect problems after POST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DSpeed
Forum Newbie
Posts: 2
Joined: Sun Feb 22, 2009 5:53 am

[SOLVED] Redirect problems after POST

Post 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?
Last edited by DSpeed on Sun Feb 22, 2009 7:02 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Redirect problems after POST

Post by requinix »

Code: Select all

header("Location : profile.php");
You've got one too many spaces in there. Yes, it matters.
DSpeed
Forum Newbie
Posts: 2
Joined: Sun Feb 22, 2009 5:53 am

Re: Redirect problems after POST

Post 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.
Post Reply