Page 1 of 1

Fatal Error concerning validation

Posted: Fri Mar 12, 2010 8:35 pm
by elehifi
Hi, I am currently running into an issue, based around one of my assignment for my internet development 1 course. Here is a breakdown of the purpose of the webpage I need to make, as well as the issue im running into. I will also link to the site, and paste the contents of the doc file.

Page Purpose:

The purpose of this webpage, is to take three user inputs, and output a table which will make a temperature conversion chart based on the starting number, the ending number, and the number at which it will increment at; ie

start = 5
end = 25
increment = 5

output would be 5, 10, 15, 20, 25.


The output comes out fine in the table, however. My validation seems to be suffering, everytime I run it with incorrect inputs (letters, not putting them in), I get this;

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 8126480 bytes) in /users/intn2201/sinclairdayt/lab6_tyler.php on line 75

I should be getting messages appearing on the page, telling me which box has which error, and why it's an error.

Here is a link to my page im using to host; http://opentech.durhamcollege.ca/~intn2 ... _tyler.php

Here is the source for it;
<?php
$title = "Lab 6: Self Refering Forms with Data Validation";
$banner = "Lab 6: Self Refering Forms with Data Validation";
include ("header.php");
?>



<?php
$errorBlankFirst="";
$errorLetterFirst="";
$errorBlankLast="";
$errorLetterLast="";
$errorBlankIncrement="";
$errorLetterIncrement="";
$result="";
$first="";
$last="";
$increment="";
$table="";
$error = "";

if ($_SERVER['REQUEST_METHOD'] == "GET")
{
$first = "";
$last = "";
$increment = "";

}
else if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$first = trim($_POST['first_number']);
$last = trim ($_POST['last_number']);
$increment = trim ($_POST['increment_number']);

if (!isset($first) || $first == "")
{
$errorBlankFirst = "You did not enter anything for the starting temperature. Please enter in a numeric digit.";
}
else if (!is_numeric($first))
{
$errorLetterFirst = "You entered a non-numeric number, Which was: " .$first. "Please re-enter numerals only.";
$first ="";
}

if (!isset($last) || $last == "")
{
$errorBlankLast = "You did not enter anything for the Last temperature. Please enter in a numeric digit.";
}
else if (!is_numeric($last))
{
$errorLetterLast = "You entered a non-numeric number, Which was:" .$last. "\nPlease re-enter numerals only.";
$second="";
}

if (!isset($increment) || $increment == "")
{
$errorBlankIncrement = "You did not enter anything for the increment for the temperature chart. Please enter in a numeric digit.";
}
else if (!is_numeric($increment))
{
$errorLetterIncrement = "You entered a number that was not numeric (i.e 0-9). Please Enter a numeric value";
$increment="";
}
if($error == "")
{
$table .= "<table border =\"1\" align =\"center\">";
$table .= "<tr><th width=\"50%\">Celsius</th>";
$table .= "<th width=\"50%\">Fahrenheit</th></tr>";

for ($count = $first; $count <= $last; $count += $increment)
{
$table .= "<tr>\n\t\t<td align=\"center\">".$count.
"&deg;</td>\n\t\t<td align=\"center\">".(9.0/5.0*$count + 32) .
"&deg;</td></tr>";
}
$table .= "</table>";
}
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
Enter the first temperature you want to display:<br/><input type="text" name="first_number" value="<?php echo $first=""; ?>" size="5" /><br/>
Enter the last temperature you want to display:<br/><input type="text" name="last_number" value="<?php echo $last=""; ?>" size="5" /><br/>
Input the number in which you want the temperatures to increment at:<br/><input type="text" name="increment_number" value="<?php echo $increment=""; ?>" size="5" /><br/>
<input type="submit" value="Convert The Temperature" />
</form>

<?php echo $table; ?>
<?php
include ("footer.php");
?>


Any help would be appreciated. Im at my wits end, and have no idea how to proceed.

Re: Fatal Error concerning validation

Posted: Fri Mar 12, 2010 9:47 pm
by requinix

Code: Select all

if($error == "")
You check for an error with the $error variable but you never change it in your script. Then

Code: Select all

for ($count = $first; $count <= $last; $count += $increment)
If $increment has letters PHP will convert it to the number 0. The loop will never end. Since you keep adding stuff to $table in that loop you run out of memory.