dimanche 3 mai 2015

$_SESSION variable getting lost somewhere........or PHP ignoring "IF...ELSEIF"

I am having a problem with getting my PHP script to correctly read and execute my "IF.....ELSEIF" conditions.

In my first file, I have the following code :

if(isset($_POST['submit'])  {

$selected_radio = $_POST['selection'];

$_SESSION['my_selection'] = $_POST['selection'];  

if (($selected_radio == '25')   {

    header("url=http://xxxxxxxxxxxxxxxxx");
    }

    elseif (($selected_radio == '50')    {

    header("url=http://xxxxxxxxxxxxxxxxx");
    }

}

That was the easy part.

If either "radio button" is selected, I have a Javascript function which opens a "new (child) window"

That's also easy.

But, then, comes the hard part : within that new window, the user has to select from another choice of radio buttons :

if(isset($_POST['submit'])  {

$selected_radio = $_POST['my_response'];

if (($_POST['my_response'] = 'yes') && ($_SESSION['my_selection'] = '25'))    
{

echo '<script type="text/javascript">window.opener.location =   
 "/PHP/25.php";setTimeout("window.close();", 1000);</script>';
            }

elseif (($_POST['my_response'] = 'yes') && ($_SESSION['my_selection'] =  
'50'))  {

 echo '<script type="text/javascript">window.opener.location = 
 "/PHP/50.php";setTimeout("window.close();", 1000);</script>';
            }

Basically, this means : if the user selects "yes" in the current (child) window, then the window closes, and the parent window re-directs to "25.php" or "50.php"..........depending on the value of the $_SESSION['my_selection'] --- which was selected earlier in the parent-window

But, for some reason, it's not working. My code is executing only the FIRST IF-condition :

if (($_POST['my_response'] = 'yes') && ($_SESSION['my_selection'] = '25'))     
{

echo '<script type="text/javascript">window.opener.location = 
"/PHP/25.php";setTimeout("window.close();", 1000);</script>';
            }

It is completely ignoring the second one.............even if the user had earlier selected "50" in the parent-window.

My first thought was : the SESSION value of the radio-button ---- $_SESSION['my_selection'] --- was not being carried-over into the new (child) window.

But, I used "echo" to verify that this was working properly. The value was indeed being carried-over into the new (child) window.

However, after the child-window closes, and the parent-window is re-directed, I used "echo" again to track any errors........and it showed that : the value of $_SESSION['my_selection'] is always equal to "25" !

In a nutshell : why is the second IF-statement being ignored??

    elseif (($_POST['my_response'] = 'yes') && ($_SESSION['my_selection'] = 
    '50'))  {

    echo '<script type="text/javascript">window.opener.location =   
    "/PHP/50.php";setTimeout("window.close();", 1000);</script>';

Aucun commentaire:

Enregistrer un commentaire