I have two pages. Page one dynamically echo's the html necessary to generate 2 radio buttons as a group. The onclick even of either button passes the value of the button to my second page which then calculates a value, updates a database, and passes back to the first page. Now, since the buttons were dynamically generated, based on what they chose before going to page two, it'd be nice to set that again for them so that it's not confusing.
Anyhow, I got the radio buttons generated just fine, they pass the parameters I expect, and I can echo out on page two the values, and they are what I expect. After I perform the calculation and database update, I echo the values yet again and again I get what I expect. Now here's the part I can't figure out: I am setting a session value on page2 for a calculated value that effects how the radio buttons on page1 are generated. If I echo this session variable out on page 2, I get results. if I call the same session variable (yes I'm aware PHP is strongly typed) on page1 I get nothing. Likewise the isset() function returns false.
Here's the code to create 2 radio buttons. The two situations are that the user has not ever selected a shipping option, or that they have and the button should be pre-selected.
Code: Select all
<?php
if(!isset($_SESSION['ShipType'])){
echo "<input type='radio' name='shipping' id='standard' value='Standard' onClick=\"location.href='addShip.php?shipping=standard&numItems=$numProducts'\"> Standard Shipping<br/>";
echo "<input type='radio' name='shipping' id='rush' value='Rush' onClick=\"location.href='addShip.php?shipping=rush&numItems=$numProducts'\"> Rush Shipping<br/>";
}
else{
if($_SESSION['ShipType'] = "standard"){
echo "<input type='radio' name='shipping' id='standard' value='Standard' onClick=\"location.href='addShip.php?shipping=standard&numItems=$numProducts'\"> Standard Shipping $".$_SESSION['ShipCost']."<br/>";
echo "<input type='radio' name='shipping' id='rush' value='Rush' onClick=\"location.href='addShip.php?shipping=rush&numItems=$numProducts'\"> Rush Shipping $".$_SESSION['ShipCost']."<br/>";
}
else{
echo "<input type='radio' name='shipping' id='standard' value='Standard' onClick=\"location.href='addShip.php?shipping=standard&numItems=$numProducts'\"> Standard Shipping $".$_SESSION['ShipCost']."<br/>";
echo "<input type='radio' name='shipping' id='rush' value='Rush' checked='true' onClick=\"location.href='addShip.php?shipping=rush&numItems=$numProducts'\"> Rush Shipping $".$_SESSION['ShipCost']."<br/>";
}
}
?>
So reading through that, my intent was that if the session variable is not set, create two buttons with neither selected. If It is set, determine which should be checked. My second page echos the ShipType session variable every time. I have session_start on both pages. Admittedly I'm new to php and I don't really care for it, it's too much like classic asp. At any rate, I'd be grateful for any insight into what is probably inexperience on my part. Thanks.