0% found this document useful (0 votes)
87 views

PHP Example

This document contains PHP code to calculate ticket costs for an event. It defines functions to handle errors for invalid adult or date inputs. The transComplete function calculates subtotals, taxes, fees and total costs based on ticket quantities. It outputs a summary of the ticket order details. The code gets values from a HTML form, performs calculations and validations, then displays a summary of the ticket order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

PHP Example

This document contains PHP code to calculate ticket costs for an event. It defines functions to handle errors for invalid adult or date inputs. The transComplete function calculates subtotals, taxes, fees and total costs based on ticket quantities. It outputs a summary of the ticket order details. The code gets values from a HTML form, performs calculations and validations, then displays a summary of the ticket order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<!

DOCTYPE html>
<html lang="en">

<head>
<!--Name: Your name
Filename:
Blackboard User Name: XXXX
Class Section: CTI.110.XXXX
Purpose: Using the flowgorithm algorithm attached complete the missing
statements of code
-->
<meta charset="utf-8" />
<title>L13 Event Form </title>

<style>
body {
color:blue;
font-size:20px
}

h1 {
color: navy;
}
ul {
list-style-type:none;
padding:0;
}
</style>

</head>
<body>

<?php

$name = $_POST['name'];
$phone = $_POST['phone'];
$childTickets = $_POST['childTickets'];
$date = $_POST['date'];

function adultError() {
echo "You must have at least one adult or 999 to QUIT" . PHP_EOL;
echo "Adult Tickets Needed" . PHP_EOL;
}

function dateEnter() {
echo "You must choose one of the allowed dates which are Mar 2021, Apr 2021 or
May 2021 or 999 to exit" . PHP_EOL;
echo "Please enter the date you wish to attend" . PHP_EOL;
}

function transComplete($adultTickets, $date, $name, $phone, $childTickets) {


define("TAX", 0.07);;
const MAXfee = 1.00;
const MINfee = .50;
const ATTENDcompare = 5;
$subtotal = 0;
$salesTax = 0;
$totalAttend = 0;
$fee = 0;
$totalCost = 0;
$totalAttend = $adultTickets + $childTickets;

if ($totalAttend <= $aTTENDcompare) {


$fee = $totalAttend * $mAXfee;
} else {
$fee = $totalAttend * $mINfee;
}
$subtotal = $adultTickets * 35 + $childTickets * 30;
$salesTax = $subtotal * $tAX;
$totalCost = $subtotal + $salesTax + $fee;
echo "Summary Title" . PHP_EOL;
echo "Thank you " . $name . " at " . $phone . ". Details of your total cost are
defined below:" . PHP_EOL;
echo "Adult Tickets: " . $adultTickets . ", Child Tickets: " . $childTickets .
" , Attending: " . $date . ", subtotal is: " . $subtotal . ", Tax is: " . $salesTax
. " Fee is $" . $fee . " for a total cost of: $ " . $totalCost . PHP_EOL;
}

echo "Adult Tickets Needed" . PHP_EOL;


$adultTickets = input();
while ($adultTickets <= 0) {
adultError();
$adultTickets = input();
}
if ($adultTickets != 999) {
dateEnter();
$date = input();
while ($date != "Mar 2021" && $date != "Apr 2021" && $date != "May 2021" &&
$date != "999") {
dateEnter();
$date = input();
}
if ($date != "999") {
echo "Name" . PHP_EOL;
$name = input();
echo "Phone Number" . PHP_EOL;
$phone = input();
echo "Child Tickets Needed" . PHP_EOL;
$childTickets = input();
transComplete($adultTickets, $date, $name, $phone, $childTickets);
finish();
} else {
finish();
}
} else {
finish();
}
?>
//Using the flowgorithm algorithm transComplete logic, create the php code
that follow the logic

//The $_POST superglobal takes the passed values from the html form input.
These values are then assigned a PHP variables name using the assignment statement.
the $_POST MUST match the name=xxx in the form input type
$name = $_POST['name'];
$phone = $_POST['phone'];
$childTickets = $_POST['childTickets'];
$date = $_POST['date'];

//Print is also considered to be a function while echo is a language


construct. Either will work for this course
print ("<h1>Summary Ticket Cost for Concert</h1>");
//The period (.) is a concatenation symbol. For Flowgorithm you used an (&)
ampersand
print ("<p>Thank you <b>".$name."</b> at <b>".$phone. "</b>. Details of your
total cost <b>$" .$totalCost. "</b> are shown below:</p>");
print("<ul><li>Adult Tickets: $adultTickets </li>");
print("<li>Child Tickets:" .$childTickets. "</li>");

print("<li>Date:</li>");

/*All languages have a way to format output. The number_format function does
this for numbers in PHP. We are asking for two decimal points since this is dollar
data*/
echo("<li>Sub-total: $".number_format($subtotal, 2)."</li>");
print("<li>Sales tax: $" "</li>");
print("<li>Fee: $".number_format($fee, 2)."</li></ul>");
echo("<ul><li><b>TOTAL:</b><b> $".number_format($totalCost,
2)."</b></li></ul>");
print ('<br><a href="student-l13-lab-project-form.html">Return to Main
Page</a>');

?>
</body>
</html>

You might also like