Re: [PHP] Conditions within a function

2002-04-16 Thread Erik Price


On Tuesday, April 16, 2002, at 11:32  AM, Scott St. John wrote:

> What I am also discovering is I have to use die; to halt execution for
> certain things.  An example, I check to see if a user is still active in
> the system, if they are not I use a header to redirect them to a page 
> that
> tells them they are inactive.
>
> if ($userActive == 0){
>   header ('Location: notice.php');
> }
>
> As is it does not work until I do this:
>
> if ($userActive == 0){
>   header ('Location: notice.php');
>   die;
> }
>

That's strange, I never have to use "die".  Try using an absolute path 
in header(), like header('Location: http://domain.com/notice.php'), that 
may fix this (not sure).  Also make sure that header() is executed 
before any HTML is output from the PHP processor, this is a common 
mistake for new PHP coders.  Even a single line of whitespace sent 
before the header() line will screw it up, and this applies to all 
header() types, not just "Location:".

Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




Re: [PHP] Conditions within a function

2002-04-16 Thread Scott St. John

On Tue, 16 Apr 2002, Erik Price wrote:
> First of all, try organizing your code using whitespace.  Here is an 
> example of the code, formatted to be a bit easier to read:

Thank you, that was Pine doing some nice formatting tricks of it's own. 

> Now, my first question, is why do you have $userID passed by parameter 
> into the function, and also globalized in the function?  I am trying to 
> understand this function but this seems like a mistake.  You should 
> probably fix this.  Also, I'm not sure what the $db variable is 
> globalized for -- why is it needed?  It isn't used in the function, as 
> far as I can see.

I see the error there and removed the global, I am moving from ASP 
functions to PHP functions and still learning.  I misunderstood the global 
statement considering that I am passing the userID to the function.  

What I am also discovering is I have to use die; to halt execution for 
certain things.  An example, I check to see if a user is still active in 
the system, if they are not I use a header to redirect them to a page that 
tells them they are inactive.  

if ($userActive == 0){
header ('Location: notice.php');
}

As is it does not work until I do this:

if ($userActive == 0){
header ('Location: notice.php');
die;
}

-Scott




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




Re: [PHP] Conditions within a function

2002-04-16 Thread Erik Price


On Tuesday, April 16, 2002, at 08:58  AM, Scott St. John wrote:

> I have been trying to organize my code better by using functions,

First of all, try organizing your code using whitespace.  Here is an 
example of the code, formatted to be a bit easier to read:

function chkFirstTime($userID)
{
global $connection,$db,$userID;

$sqlChkFirstTime = "select  fk_userID,
firstTime
fromfirstTime
where   fk_userID = '$userID'";

$resultFirstTime = mssql_query($sqlChkFirstTime, $connection);

$rowFirstTime = mssql_fetch_array($resultFirstTime);

$firstTime = $rowFirstTime["firstTime"];
if ($firstTime == "") {
include ('includes/incFirstTime.php');
}
}

Now, my first question, is why do you have $userID passed by parameter 
into the function, and also globalized in the function?  I am trying to 
understand this function but this seems like a mistake.  You should 
probably fix this.  Also, I'm not sure what the $db variable is 
globalized for -- why is it needed?  It isn't used in the function, as 
far as I can see.

> especially where I am repeating logic.  The problem seems to be when I 
> run
> a condition within the function, an if statement to check for results 
> of a
> variable.  As is the code seems to be bypasses, but if I put a die; in 
> the
> function after the line that was skipped before I get the desired 
> results.

Why don't you put "print($firstTime)" immediately after the $firstTime = 
$rowFirstTime["firstTime"] line.  It will tell you whether or not there 
is actually a value there.  If there is, then you know why your "if" 
test is failing.  If there is no variable, then you can check to see if 
your includefile is working correctly.




Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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