...

View Full Version : IF ELSE statement



jarv
03-19-2009, 02:05 PM
is this right?



IF $_SESSION['email']='true'{
header( "Location: thankyou.htm?source=Emailer1&campaignname1=MMO2574&contact=contact" );
} else {
header( "Location: thankyou.htm?contact=contact" );
}

steelaz
03-19-2009, 02:40 PM
You forgot parenthesis around if expression, and it has to be == to test equality:


if ($_SESSION['email'] == 'true') {

sea4me
03-19-2009, 11:32 PM
Try:


if ($_SESSION['email'] == 'true') {
header( "Location: thankyou.htm?source=Emailer1&campaignname1=MMO2574&contact=contact" );
}
else {
header( "Location: thankyou.htm?contact=contact" );
}

Fou-Lu
03-19-2009, 11:38 PM
Eh?


if (isset($_SESSION['email']) && $_SESSION['email']) // Always check for isset!
{
header( "Location: thankyou.htm?source=Emailer1&campaignname1=MMO2574&contact=contact" );
}
else
{
header( "Location: thankyou.htm?contact=contact" );
}


Technically the 'true' check could be false. Boolean true !== 'true', so I'd just use the shortcut check for && $_SESSION['email'] instead. This of course only works if the $_SESSION['email'] is actually set to true and not to something else, though a non-empty string is also true.
What a pain these weak languages are >.<

sarah_9
03-20-2009, 07:22 AM
You forgot parenthesis around if expression, and it has to be == to test equality:


if ($_SESSION['email'] == 'true') {


Hello,


This is the right code, add parenthesis then it will work.

Regards,
sarah_9



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum