I'm trying to create a PHP summary page for when a user submits an HTML form.
.
The form contains different options for hotel rooms. The HTML contains two radio buttons (single or double room) and checkboxes (if a guest wants to include Friday/Saturday/Sunday dinner).
Each of these options is associated to a different price: a single room is $80, a double is $60, and each meal is $8.
As of now I've succeeded in displaying the chosen options on the PHP form.
.
But I'm struggling to calculate and then display the total price as a function of which options the guest has selected.
Is there a good way to do this? Something tells me I might need to use arrays, but I haven't figured out how.
In case you wanted to take a look at the HTML Code:
<form action="ski-trip-summary.php" method="post">
<table id="mainTable">
<tr>
<td class="mainSection"><b>Housing and Meals:</b><br />
<table>
<tr>
<td><i>Room Choices</i><br />
<input name="room" type="radio" value="single" />
Single ($80)
<input name="room" type="radio" value="double" checked="checked" />
Double ($40) </td>
</tr>
<tr>
<td><i>Meals desired ($8 each):</i><br />
<table>
<tr><td>Friday Dinner</td>
<td><input name="fridayDinner" type="checkbox" /></td></tr>
<tr><td>Saturday Dinner</td>
<td><input name="saturdayDinner" type="checkbox" /></td></tr>
<tr><td>Sunday Dinner</td>
<td><input name="sundayDinner" type="checkbox" /></td></tr>
</table></td>
</tr>
</table>
</td></tr>
</table>
and the PHP code:
print 'You have signed up for a ';
if ($_POST['room'] == 'single') {
print 'single room.';
} elseif ($_POST['room'] == 'double') {
print 'double room. <br /> <br />' ;
}
print 'Your meal signups are: <br />';
if (isset($_POST['fridayDinner']) && isset($_POST['saturdayDinner']) && isset ($_POST['sundayDinner'])) {
print '<i>Friday dinner <br />' . 'Saturday dinner <br />' . 'Sunday dinner </i> <br />';
} elseif (isset($_POST['fridayDinner']) && isset($_POST['saturdayDinner'])) {
print '<i>Saturday dinner <br />' . 'Sunday dinner </i> <br />';
} elseif (isset($_POST['fridayDinner']) && isset($_POST['sundayDinner'])) {
print '<i>Friday dinner <br />' . 'Sunday dinner </i> <br />';
} elseif (isset($_POST['saturdayDinner']) && isset($_POST['sundayDinner'])) {
print '<i>Saturday dinner <br />' . 'Sunday dinner </i> <br />';
} elseif (isset($_POST['saturdayDinner']) && isset($_POST['sundayDinner'])) {
print '<i>Saturday dinner <br />' . 'Sunday dinner </i> <br />';
} else {
print '<i>No meals </i> <br /><br />';
}
Thanks so much, and I appreciate any input or suggestions on how to do this better/more elegantly!