Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need need to create a php code block at the beginning of this document with if

ID: 3742766 • Letter: I

Question

i need need to create a php code block at the beginning of this document with if statements that use the !isset() built-in function to set the default value of the variables ($cust_fName, $cust_lName, $labor_costs, $parts_cost) to an empty string (‘ ‘) if the variables do not exist, specifically the first time the page loads. Just inside of the body, you will need to add another php statement with an if loop that uses the !empty() function to determine if the $error_message is not empty in which case it will echo the contents of the $error_message variable. Use echo statements within the value attributes of the tags for the text boxes. These echo statements should display the values in the variables from the php code block at the beginning of the page. Be sure to use the htmlspecialchars() function in your echo statements to escape the output before it is sent to the browser. After adding php blocks to your html document it is necessary to save it as a php file type.

Here is what the PHP form looks like :

Dooley's Automotive

Customer First Name:
Customer Last Name:
Labor Costs:
Parts Cost:

The php block at the beginning of the document will contain five parts. The first part gets the data from the form by using the filter_input() function to access the POST request. The second part uses one long if/else if statement to validate all four user entries. All four fields are required. $labor_costs and $parts_cost must be valid floats and they must be greater than zero. Don’t forget to include a final else statement that sets $error_message equal to an empty string. The third section is an if statement that reloads the index.php page if an error message was generated in the second section. The next section is where the math takes place. Use the define() function to create a constant TAX_RATE equal to .0925 or 9.25%. You will need variables called: $subTotal, $total, $sales_tax. The final section of the php block formats the display so that all amounts print in currency format, and concatenate the $cust_fName and $custlName with a space between them into a variable called $f_cust_name. In the body of the document use echo statements to display the customer name, parts cost, labor costs, subtotal, sales tax, and total within the <span> tags.

here is the code i have so far need to calculate the php in the form any help would be great

<?php
//get the data from the form and filter input

//validate user input (not empty, not FALSE, and greater than zero)

//if loop to call index.php when error message is not empty

//do the math (use the define function to create a constant called TAX_RATE)

//format variables as strings for display as currency and concatenate
//first and last names into one customer name

?>
<!DOCTYPE html>
<html>
<head>
<title>Invoice Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<main>
<h1>Dooley's Automotive</h1>

<label>Customer's Name:</label>
<span><?php echo 'statement goes here'; ?></span><br>

<label>Labor Costs:</label>
<span><?php echo 'statement goes here'; ?></span><br>

<label>Parts Cost:</label>
<span><?php echo 'statement goes here'; ?></span><br>

<label>Subtotal:</label>
<span><?php echo 'statement goes here'; ?></span><br>
      
       <label>Sales Tax:</label>
<span><?php echo 'statement goes here'; ?></span><br>

<label>Total:</label>
<span><?php echo 'statement goes here'; ?></span><br>
</main>
</body>
</html>

Explanation / Answer

PROGRAM:

<!DOCTYPE html>

<html>

<head>

<title>Invoice Calculator</title>

<link rel="stylesheet" type="text/css" href="main.css">

</head>

<body>

<main>

<?php

$FirstName= filter_input(INPUT_POST, 'CustomerFName', FILTER_SANITIZE_STRING);;

$LastName= filter_input(INPUT_POST, 'LastName', FILTER_SANITIZE_STRING);;

$LabourCost= filter_input(INPUT_POST, 'LaborCost', FILTER_SANITIZE_STRING);

$PartsCost= filter_input(INPUT_POST, 'PartsCost', FILTER_SANITIZE_STRING);

$cust_name=$FirstName.' '.$LastName;

$subTotal=0.0;

$SalesTax=0.0;

$Total=0.0;

if($FirstName != "" and is_string($FirstName)){

if($LastName != "" and is_string($LastName)){

if($LabourCost > 0.0 and is_float((float)$LabourCost)){

if($PartsCost > 0.0 and is_float((float)$PartsCost)){

define("TAX_RATE",".0925");

$subTotal= (float)$LabourCost + (float)$PartsCost;

$SalesTax= (float)TAX_RATE * $subTotal;

$Total= $SalesTax + $subTotal;

}

else

{

echo "You have not entered Parts Cost or You have entered wrong value";

header("Location: /index.php");

exit();

}

}

else

{

echo "You have not entered Labour Cost or You have entered wrong value";

header("Location: /index.php");

exit();

}

}

else

{

echo "You have not entered Last name";

header("Location: /index.php");

exit();

}

}

else

{

echo "You have not entered First name";

header("Location: /index.php");

exit();

}

?>

<h1>Dooley's Automotive</h1>

<form action="index.php" method="POST">

<label>Customer's Name:</label>

<span> <input readonly type="text" name="CustomerFName" value="<?php echo htmlentities($cust_name); ?>"/></span> <br>

<label>Labor Costs:</label>

<span> <input readonly type="text" name="LaborCost" value="<?php echo htmlentities('$'.$LabourCost); ?>"/></span><br>

<label>Parts Cost:</label>

<span> <input readonly type="text" name="PartsCost" value="<?php echo htmlentities('$'.$PartsCost); ?>"/></span><br>

<label>Subtotal:</label>

<span><input readonly type="text" name="subtotal" value="<?php echo htmlentities('$'.$subTotal); ?>"/></span><br>

<label>Sales Tax:</label>

<span><input readonly type="text" name="salesTax" value="<?php echo htmlentities('$'.$SalesTax); ?>"/></span><br>

<label>Total:</label>

<span><input readonly type="text" name="salesTax" value="<?php echo htmlentities('$'.$Total); ?>"/></span><br>

<input type="submit" value="Goto Main Page">

</form>

</main>

</body>

</html>