I am trying to use functions to calculate the cost
i am not sure how to get my variable from my checkbox
and i need to calculate if the user is doing the one day conference he pays for one day meal plan if he does the two day conf he gets the two day meal plan and so on…
I was going to do it like if yes is checked
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<style>
body
{
color:black;
font-size:20px;
}
h1
{
color:orange;
text-align:center;
font-size:30px;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
</style>
<title>MAJOR PROJECT 1 PHP </title>
</head>
<body>
<h1>Nerd Roundup </h1>
<form method = "POST"
action = "http://localhost/Assignments php class/calculationprogress.php">
<fieldset>
<label>
Please type your first name:
</label>
<input type = "text"
name = "fName"
value = "" /> <br />
<label>
Please type your Last name:
</label>
<input type = "text"
name = "lName"
value = "" /> <br />
Please type your city:
<input type = "text"
name = "city"
value = "" /> <br />
Please type your State:
<input type = "text"
name = "state"
value = "" /> <br />
Please type your Zipcode:
<input type = "text"
name = "zipCode"
value = "" /> <br />
<label for="other">Anything else you want to add?</label>
<textarea id="other" name="other"></textarea><br />
<fieldset>
<legend>HOW MANY DAYS</legend>
<input type = "checkbox"
name = "chkOne"
value = "100.OO" /><label>ONE DAY $100.00</label>
<input type = "checkbox"
name = "chkTwo"
value = "175.00" /><label>TWO DAYS $175.00</label>
<input type = "checkbox"
name = "chkThree"
value = "325.00" /><label>THREE DAYS $325.00</label>
<br />
<fieldset>
<legend>DO YOU WANT THE MEAL PLAN?</legend>
<input type = "checkbox"
name = "mealPlan"
value = "yes" /><label>YES</label>
<input type = "checkbox"
name = "mealPlan"
value = "no" /><label>NO</label>
<br />
<br />
<h1>NERD TRACK</h1>
<select name = "track">
<option value = "PROGRAMMING TRACK">PROGRAMMING TRACK</option>
<option value = "NETWORKING TRACK">NETWORKING TRACK</option>
<option value = "SECURITY TRACK">SECURITY TRACK</option>
<option value = "WEB TRACK">WEB TRACK</option>
</select>
<button type = "submit">
place order
</button>
</fieldset>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body
{
background-color:#FF00FF;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
h1 {text-align:center;
}
</style>
<title>Assignment3</title>
</head>
<body>
<h1>Personal Information </h1>
<?php
// define the variables
$confId = rand(1,1000);
$fName = $_POST["fName"];
$lName = $_POST ["lName"];
$city = $_POST ["city"];
$state = $_POST ["state"];
$zipCode = $_POST["zipCode"];
$other = $_POST ["other"];
$chkOne = $_POST["chkOne"];
$chkTwo = $_POST["chkTwo"];
$chkThree = $_POST["chkThree"];
$mealPlan = $_POST[""];
$confTotal = 0;
$no_errors = TRUE;
$total = 0;
checkInput();
calcPrice();
printConf();
//checkInput
function checkInput() {
if (filter_has_var(INPUT_POST, "chkOne")){
print "<p>ONE DAY CONFERENCE</p> \
";
$total += filter_input(INPUT_POST, "chkOne");
}
if (filter_has_var(INPUT_POST, "chkTwo")){
print "<p>TWO DAY CONFERENCE</p> \
";
$total += filter_input(INPUT_POST, "chkTwo");
}
if (filter_has_var(INPUT_POST, "chkThree")){
print "<p>THREE DAY CONFERENCE</p> \
";
$total += filter_input(INPUT_POST, "chkThree");
}
//end $total
if (filter_has_var(INPUT_POST, "mealPlan")){
}
if (filter_has_var(INPUT_POST, "noFood")){
}
// do they want the meal plan
$track = filter_input(INPUT_POST, "track");
// what conference track are they on
if(empty($fName))
{
$no_errors = FALSE;
echo '***FIRST NAME FIELD REQUIRED***** <br />' ;
}
//get users first name
if(empty($lName))
{
$no_errors = FALSE;
echo '****LAST NAME FIELD REQUIRED***** <br /> ';
}
// get users last name
if(empty($city))
{
$no_errors = FALSE;
echo '****CITY FIELD REQUIRED***** <br /> ';
}
//get user city
if(empty($state))
{
$no_errors = FALSE;
echo '***STATE NAME FIELD REQUIRED***** <br /> ';
}
//get user state
if(empty($zipCode))
{
$no_errors = FALSE;
echo '****ZIPCODE FIELD REQUIRED***** <br /> ';
}
//get user zip code
if(empty($other))
{
$no_errors = FALSE;
echo '****TEXT FIELD REQUIRED***** <br /> ';
}
//get user additional comments
if ($no_errors == FALSE) {
echo "<br> <a href='major1progress.html'>Go back to form</a>";
}
}//end function checkInput
//beging function calculateCost
function calcPrice(){
global $total;
$confTotal =filter_input(INPUT_POST,"confTotal");
$total = filter_input (INPUT_POST, "total");
$mealPlan = filter_input (INPUT_POST, "mealPlan");
IF (! filter_has_var (INPUT_POST, "mealPlan" )){
$total =="100" ; $confTotal = $total+= 50;
}
else if ($total=="175"){ $confTotal = $total +=75;
}
else if ($total =="225"){$confTotal = $total +=100;
$no_errors == TRUE;
}}
//end function cacluclateCost
//begin function printConf
function printConf(){
global $no_errors;
$no_errors = FALSE;
if ($no_errors == TRUE) {
print " <p> $fName $lName, <br />you have registered for Nerd Roundup 2013<br />
your planned track is $track<br />
<br /> You choose -confDay<br /> with -mPlan<br />
The total cost is: \\$$total <br />
I hear the climate around $zipCode is great this time of year.
<br /> Please make sure to bring cash, or your credit card to pay for the conference on the first day<br />
Your additional comments are as follows:
$other <br /> </p>
<p>Your Nerd Roundup confirmation number is $confId .</p> <br /> \
";
}
}
//end function printConf
?>
</body>
</html>