Hey guys, soo i'm new to PHP & I'm doing a course in school. I really really really need help. I have to get three input's;start temperature, stop temperature, & how much the users wants to increment it. then validate it for these...
that the user entered numbers in each field
that the start temperature is less than the end temperature
that the temperature increment is a positive (non-zero) number
Then outputs the temperature in a table...celsius in left coloum, fahrenheit in the right coloum, and each row increments.
So i have some code here to start off with. but I have absolutely no idea where to go from here. Can you guys please help me & explain everything to so in a way that a n00b can understand.!!! Thank you in Advance.
I'm really desperate and I need this asap!
The issues i'm having is with validation & outputting the result. it is supposed to be a self-ferring form aswell... I put the how the form should be output and the end of the code. I hope you guys understand it.
<p>Please enter Start & Stop Temperatures. Temperatures entered are in °Celsius. </p>
<p>Then enter the amount in which you want the temperature to increment.</p>
<?php
//empty out error and result regardless of method that got you here
$error = "";
$result == FALSE;
if($_SERVER["REQUEST_METHOD"] == "GET"){
//default mode when the page loads the first time
//can be used to make decisions and initialize variables
$start = "";
$stop = "";
$incr = "";
}else if($_SERVER["REQUEST_METHOD"] == "POST"){
//the page got here from submitting the form, let's try to process
$num = trim($_POST["inputted_number"]); //the name of the input box on the form, white-space removed
//let's do some data validation
if(!isset($num) || $num == ""){
//means the user did not enter anything
$error = "You must enter something into the text box.";
}else if(!is_numeric($num)){
//means the user entered something, but not a number
//give them a detailed message
$error = "The value entered <u>MUST</u> be a number, you entered: " . $num;
//empty out the invalid data
$num = "";
}
if($error == ""){ //if error is an empty string
//no errors, do the math
//$result = $num . " squared is " . ($num * $num);
$result == TRUE;
}
}else{
//there were problems, concatentate the TRY AGAIN message
$error .= "<br/>Please Try Again";
}
//NOTE:
//the first two echos below show the errors or the result (these are empty the first time the page loads)
//the third of the following echo'es makes this page self-referring
//the name of the current file is outputted placed in the action of the form
//and the fourth of the following echo'es is what makes the form sticky, the
//number previously entered on the form, is automatically displayed in the value of the text input box
?>
<div id="form6">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<p>Start Temperature: <input type="text" name="start_inputted" value="<?php echo $start; ?>" size="5" />
Stop Temperature: <input type="text" name="stop_inputted" value="<?php echo $stop; ?>" size="5" />
Increment By: <input type="text" name="incr_inputted" value="<?php echo $increment; ?>" size="5" /></p>
<p><br/><input type="submit" value="I'm Feeling Lucky!" /></p>
</form>
<!-- Table markup-->
<?php
$intFConverter;
echo "<table id='pattern-style-a'>";
echo "<thead>";
echo "<tr align='center'>";
echo "<th scope='col'>Celsius</th>";
echo "<th scope='col'>Fahrenheit</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
for($celsius=-40;$celsius<=110;$celsius+=10)
{
echo "<tr align='center'>";
echo "<td>$celsius°</td>";
echo "<td>".converter($celsius)."°</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>"
?>
<?php
function converter($celsius)
{
$intFConverter=(9.0/5.0)*$celsius + 32;
return $intFConverter;
}
?>
<h2><?php echo $result; ?></h2>
<h3><?php echo $error; ?></h3>
</div>