Jump to content

Changing session value on drop down menu submit


petenaylor

Recommended Posts

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

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.