Write PHP code to process data passed from HTML form; Write PHP statements to use PHP

variables, perform mathematical operations, and use control structures to solve application problems; Use
the echo construct and printf function to display output.
Tasks:
An Internet service provider has three different subscription packages for its customers:
Internet Service Packages
Package A: For $19.95 per month, 200 hours of access are provided. Additional hours are
$0.40 per hour.
Package B: For $29.95 per month, 300 hours of access are provided. Additional hours are
$0.35 per hour.
Package C: For $39.95 per month, unlimited access is provided.
Write a web application that allows the customer to enter the letter of the package the customer has
purchased (A, a, B, b, or C, c) and the number of hours that were used in a month, validates user input,
calculates and displays the monthly charge in the browser. It also displays the amount of money the
customer would save if a different package could be chosen.
Watch the video lecture and study code example order_form.html and order_process.php.
Create two files: hw1_form.html and hw1_process.php. The file hw1_form.html provides a
HTML form for a user to enter the package name and the hours used. After the user submits the form,
hw1_process.php processes the data as required.
The specification of the assignment includes the following:
1) Display the Internet Service Packages information to the customer.
2) Display an HTML form that allows the customer to enter the letter of package and the number of
hours used. Use 0 as a default value for the hours used.
3) After the form is submitted, display the customer’s input for the package name and hours used on
a new webpage.
4) Assume we don’t use JavaScript to validate user input on the client side, the validation must be
done on the server side in the hw1_process.php file.
If the customer enters a letter other than lowercase or uppercase letter of A, B, and C, display
“Wrong package entered. Please return to the previous page and enter a valid package name.” on
the webpage.
If the number of hours is negative, display “The number of hours must be non-negative. Please
return to the previous page and enter a valid value.” on the webpage.
5) Calculate the customer’s monthly charge and display it on the webpage. The currency should be
displayed with 2 decimal places as shown in the sample output. (Hints: Use the printf function.)
6) Display how much money the customer would save if he/she switches to other packages. If there
would be no savings by switching to other packages, display “You chose the best package.”.
7) Wherever possible, use named constants instead of numbers, for example, package base cost, free
hours for a package, and additional hour cost.
8) Use an HTML fieldset to display “BCS350 Assignment 1” followed by your name on the top of
both web pages. Please see sample output below. You are free to decide the styles of your pages.

To accomplish this task, you need to create two files: `hw1_form.html` and `hw1_process.php`. Here's how you can do it:

1. Create the `hw1_form.html` file and add the following code:
```html
<!DOCTYPE html>
<html>
<head>
<title>Internet Service Provider</title>
</head>
<body>
<fieldset>
<legend>BCS350 Assignment 1 - Your Name</legend>
<h2>Internet Service Packages</h2>
<p>Package A: For $19.95 per month, 200 hours of access are provided. Additional hours are $0.40 per hour.</p>
<p>Package B: For $29.95 per month, 300 hours of access are provided. Additional hours are $0.35 per hour.</p>
<p>Package C: For $39.95 per month, unlimited access is provided.</p>
<br>
<form action="hw1_process.php" method="post">
<label for="package">Package (A, B, or C):</label>
<input type="text" id="package" name="package" maxlength="1" required>
<br>
<label for="hours">Number of hours used:</label>
<input type="number" id="hours" name="hours" min="0" value="0" required>
<br>
<input type="submit" value="Calculate Charge">
</form>
</fieldset>
</body>
</html>
```

2. Create the `hw1_process.php` file and add the following code:
```php
<!DOCTYPE html>
<html>
<head>
<title>Internet Service Provider - Results</title>
</head>
<body>
<fieldset>
<legend>BCS350 Assignment 1 - Your Name</legend>
<?php
// Constants for package costs and hours
define("PACKAGE_A_COST", 19.95);
define("PACKAGE_A_HOURS", 200);
define("PACKAGE_A_ADDITIONAL_COST", 0.40);
define("PACKAGE_B_COST", 29.95);
define("PACKAGE_B_HOURS", 300);
define("PACKAGE_B_ADDITIONAL_COST", 0.35);
define("PACKAGE_C_COST", 39.95);

// Retrieve user input from form
$package = strtoupper($_POST['package']);
$hours = intval($_POST['hours']);

// Validate user input
if ($package != 'A' && $package != 'B' && $package != 'C') {
echo "Wrong package entered. Please return to the previous page and enter a valid package name.";
exit;
}
if ($hours < 0) {
echo "The number of hours must be non-negative. Please return to the previous page and enter a valid value.";
exit;
}

// Calculate monthly charge
switch ($package) {
case 'A':
$totalCost = PACKAGE_A_COST;
if ($hours > PACKAGE_A_HOURS) {
$additionalHours = $hours - PACKAGE_A_HOURS;
$totalCost += $additionalHours * PACKAGE_A_ADDITIONAL_COST;
}
break;
case 'B':
$totalCost = PACKAGE_B_COST;
if ($hours > PACKAGE_B_HOURS) {
$additionalHours = $hours - PACKAGE_B_HOURS;
$totalCost += $additionalHours * PACKAGE_B_ADDITIONAL_COST;
}
break;
case 'C':
$totalCost = PACKAGE_C_COST;
break;
}

// Calculate savings by switching to other packages
$savingsPackageA = (($hours - PACKAGE_A_HOURS) * PACKAGE_A_ADDITIONAL_COST) - ($hours * PACKAGE_B_ADDITIONAL_COST);
$savingsPackageB = ($hours * PACKAGE_B_ADDITIONAL_COST) - ($hours * PACKAGE_C_COST);

// Display results
echo "Package: " . $package . "<br>";
echo "Hours used: " . $hours . "<br>";
echo "Monthly Charge: $" . sprintf("%.2f", $totalCost) . "<br>";
if ($savingsPackageA > 0 || $savingsPackageB > 0) {
echo "You could save $" . sprintf("%.2f", max($savingsPackageA, $savingsPackageB)) . " by switching to another package.";
} else {
echo "You chose the best package.";
}
?>
</fieldset>
</body>
</html>
```

3. Save both files in the same directory on your web server.

When a user submits the form in `hw1_form.html`, the data will be sent to `hw1_process.php` for processing. The PHP script will validate the user input, calculate the monthly charge based on the chosen package and number of hours used, and display the results on a new webpage. It will also calculate the potential savings by switching to other packages and display that information as well.