Jump to content

IF ELSE statement


jarv

Recommended Posts

well...to get rid of the syntax errors:

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

 

but what are you trying to accomplish? the above tests to see if the value of $_SESSION['email'] is equal to the string 'true'. are you just trying to see if $_SESSION['email'] has something in it? if so, i would use:

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

Link to comment
https://forums.phpfreaks.com/topic/150137-if-else-statement/#findComment-788423
Share on other sites

thanks, I'm setting a session in another page as below:

 

<?php
    // this starts the session
    session_start();

    // this sets variables in the session
    $_SESSION['email']='true';
    ?> 

 

in my form i want to say something like:

 

IF Session == true then go to a URL IF not the go elsewhere!

Link to comment
https://forums.phpfreaks.com/topic/150137-if-else-statement/#findComment-788443
Share on other sites

yes, on my index.php I have:

 

<?php
    // this starts the session
    session_start();

    // this sets variables in the session
    $_SESSION['email']='true';
    ?> 

 

and on the other page within the site containing the form submission:

 

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

 

so I go to the index.php the click through to the form, fill out the form and I always end up at: thankyou.htm?contact=contact

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/150137-if-else-statement/#findComment-788471
Share on other sites

try this:

session_start();
if ($_SESSION['email'] == 'true') {
 header( "Location: thankyou.htm?source=Emailer1&campaignname1=MMO2574&contact=contact" );
} else {
 print "Something is wrong:<pre>";
 print_r($_SESSION);
 exit;
// header( "Location: thankyou.htm?contact=contact" );
}

 

p.s. - you need session_start() on both pages

Link to comment
https://forums.phpfreaks.com/topic/150137-if-else-statement/#findComment-788472
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.