0

I'm trying to run the following code but surely missing something. Regardless the value of the "myPlan" js variable the php echo is always "Something went wrong with the chosenPlan"

    <script type="text/javascript">
    document.write("<b>JAVASCRIPT</b><br>");
    var myPlan = sessionStorage.getItem("plan");
</script>
<?php
    $myPlan = '<script>document.write(myPlan);</script>';

    if($myPlan == 'plan1'){
        echo "Chosen plan is number 1<br>";
    } elseif($myPlan == 'plan2'){
        echo "Chosen plan is number 2<br>";
    } elseif($myPlan == 'plan3'){
        echo "Chosen plan is number 3<br>";
    } else {
        echo "-- Someting went wrong with the chosenPlan --";
    }
?>
jmouk
  • 21
  • 5

1 Answers1

0

$myPlan may be undefined and hence goes into else part. May be a good idea to check the value of $myPlan that you are getting.

Amjad
  • 11
  • 3
  • this should be a comment, it doesn't answer the question – Ben Kolya Mansley Aug 26 '17 at 15:46
  • that's what I do in my original code (this one is just a snippet). when I do the echo of $myPlan it suits to what I've chosen in the previous form. but still it goes into else part. I don't understand what I'm missing... – jmouk Aug 26 '17 at 15:49