help with functions & calculations

I am trying to make a form for an upcoming technology conference…
The PHP code should make sure the user has entered (or selected) items for each area. If the user does not select something an error message must appear that asks them to go back to the form and complete all information.I want the program to use functions to calculate the cost of the conference, and to calculate the cost of meals. The functions should return the calculated costs back to the main program.
The program will also generate a random number (1 to 1000) as the user’s conference id.
The program will print out a message similar to the following:
John Smith, you have registered for three days, with a meal plan, your total cost will be $325. Please make sure to bring cash, or your credit card to pay for the conference on the first day. Your confirmation number is 999. See you soon!

[code]

body { color:black; font-size:20px; } h1 { color:orange; text-align:center; font-size:30px; } p { font-family:"Times New Roman"; font-size:20px; } MAJOR PROJECT 1 PHP

Nerd Roundup

Please type your first name:
Please type your Last name:
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 />

Anything else you want to add?

HOW MANY DAYS ONE DAY $100.00 TWO DAYS $175.00 THREE DAYS $325.00
<fieldset>
DO YOU WANT THE MEAL PLAN? YES

NO



NERD TRACK

PROGRAMMING TRACK NETWORKING TRACK SECURITY TRACK WEB TRACK place order [/code] [php] body {

background-color:#FF00FF;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:“Times New Roman”;
font-size:20px;
}
h1 {text-align:center;
}

Assignment3

Personal Information

<?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 "

ONE DAY CONFERENCE

\n"; $total += filter_input(INPUT_POST, "chkOne"); } if (filter_has_var(INPUT_POST, "chkTwo")){ print "

TWO DAY CONFERENCE

\n"; $total += filter_input(INPUT_POST, "chkTwo"); } if (filter_has_var(INPUT_POST, "chkThree")){ print "

THREE DAY CONFERENCE

\n"; $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*****
' ; } //get users first name if(empty($lName)) { $no_errors = FALSE; echo '****LAST NAME FIELD REQUIRED*****
'; } // get users last name if(empty($city)) { $no_errors = FALSE; echo '****CITY FIELD REQUIRED*****
'; } //get user city if(empty($state)) { $no_errors = FALSE; echo '***STATE NAME FIELD REQUIRED*****
'; } //get user state if(empty($zipCode)) { $no_errors = FALSE; echo '****ZIPCODE FIELD REQUIRED*****
'; } //get user zip code if(empty($other)) { $no_errors = FALSE; echo '****TEXT FIELD REQUIRED*****
'; } //get user additional comments if ($no_errors == FALSE) { echo "
Go back to form"; } }//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(){ if ($no_errors == TRUE) { print "

$fName $lName,
you have registered for Nerd Roundup 2013
your planned track is $track

You choose -confDay
with -mPlan
The total cost is: \$$total
I hear the climate around $zipCode is great this time of year.
Please make sure to bring cash, or your credit card to pay for the conference on the first day
Your additional comments are as follows: $other

Your Nerd Roundup confirmation number is $confId .


\n"; } } //end function printConf ?> [/php]

[php]

body {

background-color:#FF00FF;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:“Times New Roman”;
font-size:20px;
}
h1 {text-align:center;
}

NERD ROUNDUP 2013

AUGUST 7-10 ATLANTA, GA

<?php // define the variables $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[""]; //1 to 1000 //generate conf id number $confId = rand(1,1000); $no_errors = TRUE; $total = 0; //begin form filter if(!isset($_POST['mealPlan']) && $_POST['mealPlan'] == 'Yes') { $mealPlan== 'Yes'; $no_errors = FALSE; } function calcTotal($value) { global $total; switch ($value) { case 100: $total +=50; break; case 175: $total += 75; break; case 225: $total+=100; break; }//end switch checkInput(); calcTotal(); printConf(); //checkInput function checkInput() { if (filter_has_var(INPUT_POST, "chkOne")) { $total += filter_input(INPUT_POST, "chkOne"); } if (filter_has_var(INPUT_POST, "chkTwo")) { $total += filter_input(INPUT_POST, "chkTwo"); } if (filter_has_var(INPUT_POST, "chkThree")) { $total += filter_input(INPUT_POST, "chkThree"); } //end $total // what conference track are they on $track = filter_input(INPUT_POST, "track"); if(empty($fName)) { $no_errors = FALSE; echo '***FIRST NAME FIELD REQUIRED*****
' ; } //get users first name if(empty($lName)) { $no_errors = FALSE; echo '****LAST NAME FIELD REQUIRED*****
'; } // get users last name if(empty($city)) { $no_errors = FALSE; echo '****CITY FIELD REQUIRED*****
'; } //get user city if(empty($state)) { $no_errors = FALSE; echo '***STATE NAME FIELD REQUIRED*****
'; } //get user state if(empty($zipCode)) { $no_errors = FALSE; echo '****ZIPCODE FIELD REQUIRED*****
'; } //get user zip code if(empty($other)) { $no_errors = FALSE; echo '****TEXT FIELD REQUIRED*****
'; } //get user additional comments //begin function calculatePrice if ($no_errors == FALSE) { echo "
Go back to form"; } }//end function checkInput //begin function printConf function printConf() { $no_errors = FALSE; if ($no_errors == TRUE) { print "

$fName $lName,
you have registered for Nerd Roundup 2013
your planned track is $track
The total cost is: \$$total

Please make sure to bring cash, or your credit card to pay for the conference on the first day
Your additional comments are as follows: $other

Your Nerd Roundup confirmation number is $confId .


\n"; } }} //end function printConf ?> [/php]

using $confId = rand(1,1000); to provide the customer with a confirmation number is a bad idea as you run the risk of providing the same ref to different customers.

I suggest using time() as the ref to create a unique number.
or if you’re storing the results in a database, maybe use the insert id?

Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service