Using the Elseif statement
Posted: Thu Nov 14, 2013 10:07 pm
I am trying to change some shopping cart script for a site I developed over 5 years ago. I have a simple set up which sets a few session variables of $boothNumber and $boothCost
Cost is calculated by the $boothNumber so simply put the number of booths * the Cost of the booth which was a set variable of 130
Now my client wants to have the number of booths change the price based on how many booths they order. Here is the schedule of costs they want to implement.
1 booth 155
2 booths 285
3 booths 415
4 booths 545
5 booths 675
6 booths 805
Here is what I am trying to do with the elsif statement but am not succeeding
Cost is calculated by the $boothNumber so simply put the number of booths * the Cost of the booth which was a set variable of 130
Now my client wants to have the number of booths change the price based on how many booths they order. Here is the schedule of costs they want to implement.
1 booth 155
2 booths 285
3 booths 415
4 booths 545
5 booths 675
6 booths 805
Here is what I am trying to do with the elsif statement but am not succeeding
Code: Select all
session_start();
$_SESSION['eventDate'] = strip_tags($_POST['eventDate']);
$_SESSION['boothNumber'] = strip_tags($_POST['boothNumber']);
$_SESSION['tableNumber'] = strip_tags($_POST['tableNumber']);
//New Code for Looping through costs of booths
if($boothNumber=="1")
{
$boothCost=155;
}
else if($boothNumber=="2")
{
$boothCost=285;
}
else if($boothNumber=="3")
{
$boothCost=415;
}
else if($boothNumber=="4")
{
$boothCost=545;
}
else if($boothNumber=="5")
{
$boothCost=675;
}
else if($boothNumber=="6")
{
$boothCost=805;
}
enfif;
//$boothCost = 130;
$boothSubCost = ($_SESSION['boothNumber'] * $boothCost);
$_SESSION['boothSubCost'] = $boothSubCost;
$tableCost = 10;
$tableSubCost = ($_SESSION['tableNumber'] * $tableCost);
$_SESSION['tableSubCost'] = $tableSubCost;
$totalCost = $boothSubCost + $tableSubCost;
$_SESSION['totalCost'] = $totalCost;
setlocale(LC_MONETARY, 'en_US');
?>