Micaela's Fabric Calculator
CODE FOLLOWS
<?php
include('../includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
echo('<h1>Micaela\'s Fabric Calculator</h1>');
// Note the variables being passed via the POST ternary operators.
$step = isset($_POST['step']) ? $_POST['step'] : 0;
$inches = isset($_POST['inches']) ? $_POST['inches'] : '';
// filter all input
$step = htmlentities($step);
$inches = htmlentities($inches);
if ($step == 0) // first time into this form
{
?>
<form action="fabrictoyards.php" method="POST">
<label for="inches">Enter Inches of Fabric</label>
<input type="text" size="36" id="inches" name="inches" value="">
<br><br>
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Calculate">
</form>
<?php
}
else // else show what the form gathered
{
echo('<p>The following is what the form gathered</p>');
echo('<pre>');
print_r($_POST);
echo('</pre>');
// CALCULATION
$yards = round($inches / 36, 2);
echo("<h3>$inches inches is equal to $yards yards.</h3>");
echo('<br>');
echo('<img src="../images/seamstress-sewing-machine.gif" alt="Fabric animation" width="300">');
?>
<form action="fabrictoyards.php" method="POST">
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Try Again">
</form>
<?php
}
include('../includes/footer.php');
?>