Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $title = "Lab 6 - Self-referring Forms w/ Data Validation";
- $file = "lab6.php";
- $description = "This lab page will have an HTML form that refers back to itself, and will use PHP to handle data validation.";
- $date = "Date: March 23, 2018";
- $banner = "Lab 6: Self-referring Forms w/ Data Validation";
- include 'header.php'; //moved this to here
- define('MAX_ITERATIONS','100');
- $start = "";
- $stop = "";
- $incr = "";
- $error = "";
- $output = ""; //changed this from $result
- if ($_SERVER["REQUEST_METHOD"] == "post")
- {
- $start = trim($_POST["startTemp"]);
- $stop = trim($_POST["stopTemp"]);
- $incr = trim($_POST["incrRate"]);
- if(!isset($start) || $start == "")
- {
- $error .= "You need to enter a starting value.";
- }
- else if(!is_numeric($start))
- {
- $error .= "You need to enter a number in the initial value box.";
- $start = "";
- }
- if(!isset($stop) || $stop == "")
- {
- $error .= "You need to enter an ending value.";
- }
- else if(!is_numeric($stop))
- {
- $error .= "You need to enter a number in the final value box.";
- $stop = "";
- }
- if(!isset($incr) || $incr == "")
- {
- $error .= "You need to enter an increment rate.";
- }
- else if(!is_numeric($incr))
- {
- $error .= "You need to enter a number in the increment rate box.";
- $incr = "";
- }
- if((($stop - $start)/$incr) > MAX_ITERATIONS)
- {
- $error .= "The maximum number of iterations has been exceded. Please enter a lower increment rate";
- }
- else
- {
- if($error == "" && $_SERVER["REQUEST_METHOD"] == "post")
- {
- $output = "<table border='2px'>";
- $output .= "<tr>";
- $output .= "<th>Celcius</th>";
- $output .= "<th>Fahrenheit</tr>";
- $output .= "</tr>";
- for($celc = $start; $celc <= $stop; $celc += $incr)
- {
- $fahr = (9.0 / 5.0) * $celc + 32;
- $output .= "<tr><td align='center'>$celc°</td><td align='center'>$fahr°</td></tr>";
- }
- $output .= "</table>"; //missed ;
- }
- else
- {
- $error .= "<br/>Please try again.";
- }
- }
- }
- ?>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
- Enter your initial value: <input type="text" name="startTemp" value="<?php echo $start; ?>" size = "5" /><br/>
- Enter your final value: <input type = "text" name = "stopTemp" value = "<?php echo $stop; ?>" size = "5" /><br/>
- Enter your initial value: <input type = "text" name = "incrRate" value = "<?php echo $incr; ?>" size = "5" /><br/>
- <input type = "submit" value = "Create Temperature Conversion Table" />
- </form>
- <h2><?php echo $output; ?></h2>
- <h3><?php echo $error; ?></h3>
- <?php include 'footer.php'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement