Re: header("Location:...") fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/1/13 Richard S. Crawford <rscrawford@xxxxxxxxxxxx>
>
> Here is a snippet of code that is going to be the death of me:
>
> ------------------------------------------------------------
> //  Create a new project
> $projectcode = strtoupper(addslashes($_POST['projectcode']));   //  project
> code
>
> //  Make sure the project code is unique
> if (!$existingproject = mysql_query("select * from pb_versions where
> projectcode like '".strtoupper($projectcode)."'")) {
>    die ("Could not check for existing project code!<br />".mysql_error());
> }
>
> $numprojects = mysql_num_rows($existingproject);
>
> if ($numprojects > 0) {
>    $pid = mysql_result($existingproject,0,"versionID");
>    header("Location:managebudget.php?e=1&pid=$pid");
> }
> ------------------------------------------------------------
>
> Now, even if $numprojects is 1, 2, 3, etc., the header() command is not
> executed. Strangely, a header("Location") command later on in the script
> *is* executed. I've output the value of $numprojects, so I know that it's
> greater than 0, so the command
> header("Location:managebudget.php?e=1&pid=$pid"); *should* be executed...
> but it isn't. (Weirdly, if I put a die() command *after* this header()
> command, it works... but it seems pathologically inelegant to do so.)

There's nothing in wrong in putting a die command after the
header("Location"). In fact, it is common. The header() command by
itself don't imply in the send of the request. You can have many
header() commands in sequence, and the header will be sent only in the
end of the process.

Cheers,
Bruno.

>
> Obviously, I'm missing something incredibly basic. Can anyone help me figure
> this out?
>
>
> --
> Richard S. Crawford (rscrawford@xxxxxxxxxxxx)
> http://www.mossroot.com
> Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux