Hello, i'm new in PHP so i dont know much about it so ill need a little help with this "eazy" problem. I need to calculate the total price of the items on selected radio button and checkboxes . here is my code:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Show selected items</title> </head> <body> <?php
if ($_POST) { // Store the form data in variables and trim unwanted spaces foreach ($_POST as $key => $value) {
${$key} = $value; }
//Initialise the error message to an empty string
$errors = "";
//Check if the first name has been entered
if ($first_name == ""){
$errors .= "Please enter your first name.<br>";
}
//Check if the last name has been entered
if ($last_name == ""){
$errors .= "Please enter your last name.<br>";
}
//Check if the phone number has been entered as a number
if (is_numeric($phone_number) == FALSE){
$errors .= "Please enter a valid phone number (numbers only).<br>";
}
//Inform user about any missing details
if ($errors != "") {
echo "<p>Some of the required information has not been supplied.<br>";
echo $errors;
echo "Please click the browser's back button to try again.</p>";
}
else {
// Display the form data
echo <<<END <p>First name: $first_name<br> <br>Last name: $last_name<br> <br>Phone Number: $phone_number<br> END; } }
//Check if any radio buttons were selected
if (isset($_POST['mtype'])) {
echo "<p>Membership type: ".$_POST['mtype']; //Display selected value
}
//Check if any checkboxes were selected
if (isset($_POST['extras'])) {
echo "<p>You selected the following extras.</p>";
//Get the array
$extras_array = $_POST['extras'];
//Display the selected checkbox as a list
echo "<ul>";
foreach ($extras_array as $extras){
echo "<li>$extras";
}
echo "</ul>";
} else { echo "<p>You selected no extra services.</p>"; }
//Calculating cost
?> </body> </html>
Base fee for radio buttons are: Adult:$250, Child:$150, Concession:$150
I havent made my mind up what prices the checkboxes will be but it would be a great help if you can just tell me how to add the cost (of the selected checkboxes) up to the radio button. E.g
If user chose Adult ($250) then Checkbox1 Checkbox2 Checkbox3 = 250 + * + * + * = ?
Bruce_7 0 Newbie Poster
diafol
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.