I have created a reservations page for a restaurant website, with a form present to book a dinner reservation. It contains a dropdown box which allows the user to select the amount of people who will be dining in their party. It also contains a radio button to allow the user to select if they wish to be seated in the VIP area.
Once the form validation is successful, the user will be sent to a confirmation page, where the reservation details they have entered, will be displayed to them.
Each person in the party should cost an extra £5 towards their booking fee and if they wish to be seated in the VIP area, they will be charged an additional £5.
I wish to add these two factors together and display a total booking fee to the user on the confirmation page, but the code I have currently, is not performing this.
Here is the relevant code on my reservations page:
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['party'] = $_POST['party'];
}
if ( !empty($_POST['vip']))
$_SESSION['vip'] = $_POST['vip'];
?>
...
<strong>Select Party Size* :</strong>
<br>
<select name="party" id="party" value="<?php echo $party;?>">
<option value="">Please Select</option>
<option <?php if (isset($party) && $party=="1") echo "selected";?> value="1">1 Person (+£5)</option>
<option <?php if (isset($party) && $party=="2") echo "selected";?> value="2">2 People (+£10)</option>
<option <?php if (isset($party) && $party=="3") echo "selected";?> value="3">3 People (+£15)</option>
<option <?php if (isset($party) && $party=="4") echo "selected";?> value="4">4 People (+£20)</option>
<option <?php if (isset($party) && $party=="5") echo "selected";?> value="5">5 People (+£25)</option>
<option <?php if (isset($party) && $party=="6") echo "selected";?> value="6">6 People (+£30)</option>
<option <?php if (isset($party) && $party=="7") echo "selected";?> value="7">7 People (+£35)</option>
<option <?php if (isset($party) && $party=="8") echo "selected";?> value="8">8 People (+£40)</option>
<option <?php if (isset($party) && $party=="9") echo "selected";?> value="9">9 People (+£45)</option>
<option <?php if (isset($party) && $party=="10") echo "selected";?> value="10">10+ People (+£50)</option>
</select>
<strong> VIP area* : </strong> <br><br>
Yes (+£5) <input type="radio" name="vip" <?php if (isset($vip) && $vip=="Yes") echo "checked";?> value="Yes">
<br><span id="vip" class="error"><?php echo $vipErr;?></span><br>
No <input type="radio" name="vip" <?php if (isset($vip) && $vip=="No") echo "checked";?> value="No">
Here is the relevant code on my confirmation page:
<b>Total Reservation Costs: </b> £
<?php
if (isset($_POST['party']) && is_numeric($_POST['party'])) {
$party = (int)$_POST['party'];
$vip = isset($_POST['vip']) ? 5 : 0;
echo "Total is: " . (($party * 5) + $vip);
}
?>
Currently no calculation is echoed, would anyone be able to correct my code so I can understand what I did wrong? Thank you
"your answer has not provided with me a solution to my problem". Clearly it answered your question as you have copied it into this one and this one stackoverflow.com/questions/27078470/…. Note how your original question (stackoverflow.com/questions/27050838/adding-two-variables-php) made no mention ofsessions. S.O. is not a place to have people write your entire application for you. A point I tried to make before when you sent me links to pastebin and asked me to fit my answer into the rest of your code.