Jump to content

Creating a sign up form for a conference


webdevdea
Go to solution Solved by webdevdea,

Recommended Posts

 The program MUST 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.

I am trying to use checkboxes to for the input.. Im new to all of this trying to get it right.. 

<!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 = "mealPlan" /><label>YES</label>
        
  <input type = "checkbox"
         name = ""
         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
$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;

 
//begin form filter

if (filter_has_var(INPUT_POST, "chkOne")){
  print "<p>ONE DAY CONFERENCE</p> \n";
  $total += filter_input(INPUT_POST, "chkOne");
  
}

if (filter_has_var(INPUT_POST, "chkTwo")){
  print "<p>TWO DAY CONFERENCE</p> \n";
  $total += filter_input(INPUT_POST, "chkTwo");
  
}

if (filter_has_var(INPUT_POST, "chkThree")){
  print "<p>THREE DAY CONFERENCE</p> \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***** <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>";
} // check the fields are all filled if not direct back to form page
//beging function calculateCost

function calculateCost()
	global $total; 
	$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;
	}
//end function cacluclateCost



  
   //end if
  //1 to 1000

$confId = rand(1,1000);
//generate conf id number






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: \$$confTotal <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 /> \n";

 }
 //check and see is the form filled out if it is then print stuff



   



?>

</body>
</html> 
//beging function calculateCost

function calculateCost()
	global $total; 
	$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;
	}
//end function cacluclateCost
Link to comment
Share on other sites

PHP working on my functons.. see the HTML above 

<!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> \n";
  $total += filter_input(INPUT_POST, "chkOne");
  
}

if (filter_has_var(INPUT_POST, "chkTwo")){
  print "<p>TWO DAY CONFERENCE</p> \n";
  $total += filter_input(INPUT_POST, "chkTwo");
  
}

if (filter_has_var(INPUT_POST, "chkThree")){
  print "<p>THREE DAY CONFERENCE</p> \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***** <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(){
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 /> \n";

 }
 	}
 //end function printConf



   



?>

</body>
</html> 
Link to comment
Share on other sites

Seeing as this is a school project, I won't tell you how to fix this completely. I will, however, give you hints as what you should look at. Seeing as one tends to learn best by figuring out the problem, and its solution, oneself. ;)

 

First order of business would probably be to fix your indentation and use of white space, both in the HTML code and the PHP code. Having it properly indented and using a consistent style makes it a lot easier to spot problems, as they tend to break the established pattern. Not to mention it'll help you keep track of what happens when, as you'll have a visual clue to help you group the logic of the code.

 

Second order of business would be to remove all uses of the global keyword. I won't go into all of the reasons, but trust me when I say that it's one of the primary causes for some of the hardest bugs to track.

I recommend reading up on how to pass function parameters and returning values, as that is how you should be doing it.

 

Then you'll want to do some proper input validation on the data you're getting from the form. Right now you're attempting to use the data, before you've even verified their existence. (Assigning to a variable is using.) At the very least you should be checking if a form has actually been submitted, before you run through the code to process said form.

isset and the filter_var functions are two cornerstones in how to perform input validation. Just remember to validate input as the first thing you do, even before assigning it to another variable from the $_POST or $_GET arrays.

 

After you've fixed the indentation, you should already have noticed one of the reasons you're getting an error message. (If you don't see an error message, read the links in Jessica's signature.)

That should also make you aware of another problem you have, one of logic. Now this is the hardest part. Spotting logic errors means that you don't only have to understand what the code actually does (as opposed to as what you wanted it to do), but you also have to understand the problem and the correct solution to it. Only after you've understood the problem fully, and solved it, will you be able to write the correct code to replicate/automate said solution.

 

That said, you really want to take a look at the first IF-test of your calculateCost () function.

 

Bonus hint: If you move all of the processing PHP code to above the first line of HTML, your script is not bound to what you've already sent to the client. Enabling you to use the really nifty header function. ;)

Something which will help make your script a lot more flexible, and easier to write.

Link to comment
Share on other sites

Working on it.. is this any better? 

<?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;
}

checkInput();
calcPrice();
printConf();

 
//checkInput
function checkInput() {

if (filter_has_var(INPUT_POST, "chkOne")){
  print "<p>ONE DAY CONFERENCE</p> \n";
  $total += filter_input(INPUT_POST, "chkOne");
  
}

if (filter_has_var(INPUT_POST, "chkTwo")){
  print "<p>TWO DAY CONFERENCE</p> \n";
  $total += filter_input(INPUT_POST, "chkTwo");
  
}

if (filter_has_var(INPUT_POST, "chkThree")){
  print "<p>THREE DAY CONFERENCE</p> \n";
  $total += filter_input(INPUT_POST, "chkThree");
  
}
//end $total 




$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(){
 
	$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(){
$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 />
			The total cost is: \$$total <br />
			<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 /> \n";

 }
 	}
 //end function printConf



   



?>
Link to comment
Share on other sites

I reconstructed it some and added a switch statement to calculate the values

<!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>NERD ROUNDUP 2013</title>
</head>
<body>

<h1>AUGUST 7-10 ATLANTA, GA </h1>

<?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)
{	 $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***** <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
//begin function calculatePrice


	
if ($no_errors == FALSE) 
{

echo "<br> <a href='major1progress.html'>Go back to form</a>";
} 
}//end function checkInput
//begin function printConf
function printConf()
{
$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 />
			The total cost is: \$$total <br />
			<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 /> \n";

 }
 }}
 //end function printConf


?>

</body>
</html> 
Link to comment
Share on other sites

Like Christian said, we don't normally answer homework questions. So, it'll be up to you to determine if it's better.

 

Is it?

Well I reconstructed it some, I added a switch statement to calculate the values but its still not right. 

Link to comment
Share on other sites

I think you need to go back to the basics, as you clearly don't understand how PHP works.

Just throwing code together, in the hopes that it'll work, isn't programming. Worse, it will create an enormous amount of trouble for you, trouble which you will not be able to figure out on your own.

 

Anything you're unsure about in my first post you'll have to search for information on, and read up on every single detail of it. Otherwise you're just flailing about, drowning without even an attempt at swimming.

Link to comment
Share on other sites

Ok so I just started over, I am working on the calculation process first and then going to add the simple part.. 

Its not calculating correctly, if someone could point me to a site, link or something that simply explains what I am trying to do, it would be most wonderful, the book I have is not explaining. 

<!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>
<title>calculate cost of convention</title>
<link rel = "stylesheet"
      type = "text/css"
      href = "checkDemo.css" />
</head>
<body>
<h1>how many days</h1>

<h2>calculate cost of convention</h2>

<form action = "http://localhost/Assignments php class/calculate.php"
      method = "post">

<fieldset>
  <legend>How Many Days</legend>
  <input type = "checkbox"
         name = "oneDay"
         value = "100" /><label>oneDay</label>
  <input type = "checkbox"
         name = "twoDays"
         value = "175" /><label>twoDays</label>
  <input type = "checkbox"
         name = "threeDays"
         value = "225" /><label>threeDays</label>
    
	<fieldset>
 Please Check If you would Like The Meal Plan Added to your total. 
    <input type="checkbox" name="mealPlan" value="Yes" />
<br />
<br />


  <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>
<title>calculate please</title>
</head>

<body>
<?php

$confId = rand(1,1000);
//meal plan 

if(!isset($_POST['mealPlan']) && 
   $_POST['mealPlan'] == 'Yes') 
{	$mealPlan== 'Yes';
     $no_errors = FALSE;
}





{
if (filter_has_var(INPUT_POST, "oneDay")){
  print "<p>You wanted oneDay</p> \n";
  $total += filter_input(INPUT_POST, "oneDay");
}

if (filter_has_var(INPUT_POST, "twoDays")){
  print "<p>You wanted  twoDays</p> \n";
  $total += filter_input(INPUT_POST, "twoDays");
}

if (filter_has_var(INPUT_POST, "threeDays")){
  print "<p>You wanted threeDays</p> \n";
  $total += filter_input(INPUT_POST, "threeDays");
}

else


 	if ($total == 100 && $mealPlan =='Yes');
 {$total += 50;
 } 




 
 	if ($total == 175  && $mealPlan =='Yes');
 {
 	($total += 75);
 	}

 

 if ($total == 225 && $mealPlan =='Yes');
 {
 ($total += 100);
 }}
  


 



print "<p>The total cost is: \$$total</p> \n
		our Nerd Roundup confirmation number is  $confId .</p> <br /> \n";
?>
</body>
</html>

Link to comment
Share on other sites

Ok so I am getting closer. 


	
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>calculate please</title>
</head>
 
<body>
<?php
//generate random confirm number
$confId = rand(1,1000);
 
 
 // Variables for storing data and calculations
$errors = "";
$count = 0;
$cost = 0;
 
 
// Function to display errors
function errorMessage($errors)
{
echo "<p>Your order could not be completed. Please check the errors below:<br />";
echo "<ul>";
    echo $errors;   // Display error message
echo "</ul>";
    echo "<br> <a href='testing.html'>Go back to form</a>";
   }
   if(!isset($_POST['mealPlan']) && 
   $_POST['mealPlan'] == 'Yes') 
{ $mealPlan== 'Yes';
}
  
  // if the form has been posted,analze it
if($_POST)
{ foreach ($_POST as $field_name => $value)
{ $value = is_array($value) ? $value : trim($value); 
$$field_name = $value; 
}
// Testing for input errors and nil entries in the various areas of the form
 
if($first_name == "" || is_numeric($first_name))
{
$errors .= "<li>a first name needs to be entered</li><br />";
}
if($last_name == "" || is_numeric($last_name))
{
$errors .= "<li>a last name needs to be entered</li><br />";
}
if($phone === "" || is_numeric($last_name))
{
$errors .= "<li>a phone number needs to be entered</li><br />";
}
 
 
$cost =0;
if($base == "")
{
$errors .= "<li>How Many Days Are You Attending the Convention?</li><br />";
}
if($base == "One" && $mealPlan =="Yes");
{
$cost = 100 + 50;
}
if ($base == "One") {
$cost = 100;
 
}
 
if($base == "Two" && $mealPlan =="Yes");
{
$cost = 175 + 75;
}
if ($base == "Two") {
$cost = 175;
 
}
 
if($base == "Three" && $mealPlan =="Yes");
{
$cost = 225 + 100;
}
if ($base =="Three") {
$cost = 225;
}
 
 
/*   for($i = 0; $i < 6; $i++)
{
if($extra_arr[$i])
{
$count++;//
}
 
}
*/
$count = count($extra);
// If no errors, display the form data
if($errors == "")
{
echo <<<END
<p>First name:  $first_name</p>
<p>Last name:  $last_name</p>
<p>Phone:  $phone</p>
<p>Days :   $base</p>
   
<ul>
END;
 
 
 
echo <<<END
</ul>
<p>Your Nerd Roundup confirmation number is  $confId .</p> <br /> \n
    Cost: $$cost</p>
END;
}
else // If errors, display errors
{
errorMessage($errors);
}
?>
</body>
</html>
 
Link to comment
Share on other sites

  • Solution

Ok so now I have this and it actually works, but how can I clean it up and get me some functions out of it??? Please and thank you ..  

<!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
{

background-color:green;
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</title>

</head>
<body>
<h1> NERD ROUNDUP TECHNOLOGY CONVENTION </h1>

<h1>AUGUST 7-10 ATLANTA GA </h1>




  <p>
    Welcome To The Nerd Roundup 2013. Complete the form below to calculate the cost of your conference package
  </p>
  <form action="testing.php" method="post">
   	<table  width="750" border="0" cellpadding="0" cellspacing="0"> 
		<table  width="750" border="0" cellpadding="0" cellspacing="0"> 
		  <tr>
			<td width="88">First name: </td>
			<td width="662"><input type="text" id="first_name" name="first_name" size="30" maxlength="20" /></td>
		  </tr>
		  <tr>
			<td>Last name: </td>
			<td><input type="text" id="last_name" name="last_name" size="30" maxlength="20" /></td>
		  </tr>
		  <tr>
			<td>Phone: </td>
			<td><input type="text" id="phone" name="phone" size="10" maxlength="10" /></td>
		  </tr>
	</table>
	
	 <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>
  <br />
  
		<p>How Many Days Will Your Attend Conference:<br>
		  <input type="checkbox" id="One" name="base" value="One"> <label for="one">One Day</label><br />
		  <input type="checkbox" id="Two" name="base" value="Two"> <label for="two">Two Day</label><br />
		  <input type="checkbox" id="Three" name="base" value="Three"> <label for="three">Three Day</label><br />
		
		  
		  
		</p>
		
	<fieldset>
 Please Check If you would Like The Meal Plan Added to your total. 
    <input type="checkbox" name="mealPlan" value="Yes" />
<br />
<br />
		<p>
		 <input type="image" src="codercat.jpg" name="image" width="60" height="60"><br />
		 Click ^ Codercat to Submit
		</p>
		
  </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">

<style>

body
{

background-color:green;
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</title>

</head>
<body>
<h1> NERD ROUNDUP TECHNOLOGY CONVENTION </h1>

<h1>AUGUST 7-10 ATLANTA GA </h1>
<?php
//generate random confirm number
$confId = rand(1,1000);
// Variables for storing data and calculations
	$errors = "";
	$count = 0;
	$cost = 0;
	$base = "";
	$mealPlan = "";
global $base, $mealPlan;
// Function to display errors
	function errorMessage($errors) 			
	{
		echo "<p>Your order could not be completed. Please check the errors below:<br />";
		echo "<ul>";
    	echo $errors;   						// Display error message
		echo "</ul>";
    	echo "<br> <a href='Assignment30.html'>Go back to form</a>";
   }
 // if the form has been posted,analze it
	 if($_POST)
	{	foreach ($_POST as $field_name => $value)
		{	$value = is_array($value) ? $value : trim($value); 
			$$field_name = $value; 
			} 
	}
// Testing for input errors and nil entries in the various areas of the form
			
	if($first_name == "" || is_numeric($first_name))
	{
		$errors .= "<li>a first name needs to be entered</li><br />";
	}
	if($last_name == "" || is_numeric($last_name))
	{	$errors .= "<li>a last name needs to be entered</li><br />";
	}
	if($phone === "" || is_numeric($last_name))
	{	$errors .= "<li>a phone number needs to be entered</li><br />";
	}

  if(!isset($_POST['mealPlan']) && 
   $_POST['mealPlan'] == 'Yes') 
{	$mealPlan== 'Yes';
}

		if($base == ""){
		$errors .= "<li>How Many Days Are You Attending the Convention?</li><br />";
	}
	if($base == "One") 
	{	$cost = 100;} 
	if ($base == "One" && $mealPlan =="Yes")
	{ $cost = 100 + 50;
	}
	
	if($base == "Two" )
	{	$cost = 175;}
	if ($base == "Two" && $mealPlan =="Yes")
	{ $cost = 175 + 75;
	}
	
	
	
	if($base == "Three")
	{	$cost = 225;}
	if ($base == "Three" && $mealPlan =="Yes")
	{ $cost = 225 + 100;
	}

	
	
	
/*  	for($i = 0; $i < 6; $i++)
	{
		if($extra_arr[$i])
		{	
			$count++;//
		}
	
		 }
*/
$count = count($extra);
	// If no errors, display the form data
	if($errors == "")
	{
echo <<<END
	<p>$first_name $last_name thank you for your interest.</p>
	<p>You have registered for $base day(s) at our Technology Conference</p>
	<p> You choose  $track as for your track of interest.</p>
	<p>Please bring cash or your credit card the first day for payment.</p>
	<p> your Confirmation number is $confId</p>
	<p> Your total cost including your meal plan option is$$cost</p>
	<p> We look forward to your participation</p>
   
	<ul>
END;



echo <<<END
	</ul>
	
END;
	}
	else						// If errors, display errors
	{
		errorMessage($errors);
	}
?>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.