petenaylor Posted October 10, 2010 Share Posted October 10, 2010 Hi all I am trying to write a piece of code that allows a user to select a country from the drop down menu and them submit it so that it changes the delivery cost in the session. Here's the code for the drop down menu: echo "<form method=\"post\" action=\"basket.php\">"; echo "<select name=\"postal_area_name\" >"; echo "<option value=\"\">--Please Select--</option>"; echo "<option value=\"England\">England</option><option value=\"Scotland\">Scotland</option><option value=\"Wales\">Wales</option>"; echo "</select>"; echo "<input type=\"submit\" name=\"submit_postal_area\" value=\"Go\" class=\"go\">"; echo "</form>"; Then here's my code to grab the delivery change from the form: if(isset($_POST['postal_area_name'])) { $_SESSION['postal_area'] = ($_POST['postal_area_name']); header("Location: basket.php"); exit; } Then this is to set the session price: if(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "England") { $set_delivery = "5.95"; } elseif(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "Wales") { $set_delivery = "10.00"; } elseif(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "Scotland") { $set_delivery = "20.00"; } else { $set_delivery = "5.95"; } $subtotal += $set_price * $qty; $delivery += $set_delivery * $qty; Then I echo out the $delivery in the basket. This doesn't seem to update, it shows the value as being 0 all the time? Please help Thanks Pete Link to comment https://forums.phpfreaks.com/topic/215555-changing-session-value-on-drop-down-menu-submit/ Share on other sites More sharing options...
Pikachu2000 Posted October 10, 2010 Share Posted October 10, 2010 Have you remembered to call session_start() at the beginning of any script that makes use of $_SESSION vars? Link to comment https://forums.phpfreaks.com/topic/215555-changing-session-value-on-drop-down-menu-submit/#findComment-1120841 Share on other sites More sharing options...
petenaylor Posted October 10, 2010 Author Share Posted October 10, 2010 Yes it's in my header at the start of every page Link to comment https://forums.phpfreaks.com/topic/215555-changing-session-value-on-drop-down-menu-submit/#findComment-1120845 Share on other sites More sharing options...
Pikachu2000 Posted October 10, 2010 Share Posted October 10, 2010 echo $_SESSION['postal_area'] before the if/elseif/else conditionals in the third code chunk to make sure it has a value. Link to comment https://forums.phpfreaks.com/topic/215555-changing-session-value-on-drop-down-menu-submit/#findComment-1120847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.