PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
paycheck
Forum Newbie
Posts: 3 Joined: Thu Nov 14, 2013 9:39 pm
Post
by paycheck » 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
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');
?>
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Nov 14, 2013 10:11 pm
Code: Select all
$boothCost = (130 * $boothNumber) + 25;
paycheck
Forum Newbie
Posts: 3 Joined: Thu Nov 14, 2013 9:39 pm
Post
by paycheck » Thu Nov 14, 2013 10:49 pm
A start but it is not calculating correctly
Code: Select all
The result is 100.00 when using this set up
$boothCost = (130 * $boothNumber) + 25;
$boothSubCost = ($_SESSION['boothNumber'] * $boothCost);
$_SESSION['boothSubCost'] = $boothSubCost;
$tableCost = 10;
$tableSubCost = ($_SESSION['tableNumber'] * $tableCost);
$_SESSION['tableSubCost'] = $tableSubCost;
$totalCost = $boothSubCost + $tableSubCost;
$_SESSION['totalCost'] = $totalCost;
paycheck
Forum Newbie
Posts: 3 Joined: Thu Nov 14, 2013 9:39 pm
Post
by paycheck » Thu Nov 14, 2013 10:56 pm
paycheck wrote: A start but it is not calculating correctly
Code: Select all
The result is 100.00 when using this set up
$boothCost = (130 * $boothNumber) + 25;
$boothSubCost = ($_SESSION['boothNumber'] * $boothCost);
$_SESSION['boothSubCost'] = $boothSubCost;
$tableCost = 10;
$tableSubCost = ($_SESSION['tableNumber'] * $tableCost);
$_SESSION['tableSubCost'] = $tableSubCost;
$totalCost = $boothSubCost + $tableSubCost;
$_SESSION['totalCost'] = $totalCost;
Got it, with your help.
Code: Select all
session_start();
$_SESSION['eventDate'] = strip_tags($_POST['eventDate']);
$_SESSION['boothNumber'] = strip_tags($_POST['boothNumber']);
$_SESSION['tableNumber'] = strip_tags($_POST['tableNumber']);
$boothCost = 130;
$boothSubCost = ($_SESSION['boothNumber'] * $boothCost +25);
$_SESSION['boothSubCost'] = $boothSubCost;
$tableCost = 10;
$tableSubCost = ($_SESSION['tableNumber'] * $tableCost);
$_SESSION['tableSubCost'] = $tableSubCost;
$totalCost = $boothSubCost + $tableSubCost;
$_SESSION['totalCost'] = $totalCost;
setlocale(LC_MONETARY, 'en_US');
?>
instead of adding the calculation to the booth cost, I added it to the booth sub cost and now it works perfectly
Thank you