I need help with a PHP calculation page?

Brian Gagnon

New member
I have an html form that links to a php page that is supposed to do a calculation but all I get when the calculation button is pressed is a new php page that skips the calculation and tells the user to use their browser's back button. Here is the code. I really need the help.

HTML form

<form action="BG_Calculation.php" method="POST">
Estimated time to complete project in hours: <input name="num1" type="text" /><br>
<input type="submit" value="Calculate"/>
</form>


PHP page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Gagnon Partnership Calculation</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
/*This is the php code that makes the calculation that the form uses
to calculate the cose of the project*/
//Brian Gagnon
# 12/6/2010
$num1 = $_POST['num1'];
$num2 = 140;
$submit = isset($_POST['submit']);
if($submit) {
if(is_numeric($num1))
{
$a = $num1 * $num2;
echo "The cost of the project is " . $a;
}
else
{
$a = "Invalid number.";
echo $a;
}
}
echo "Use your browser's back button to return to the last page";
?>
</body>
</html>
 
How to calculate the page loading time?


Need to calculate your page load speed with PHP? These two sniplets of code will calculate the amount of time, your page has taken to load in milliseconds. Place this first code as far north on your page, as possible.

view sourceprint?

1<?php
2 $time = explode(" ",microtime());
3 $pagestart = $time[0] + $time[1];
4?>


Place this second code as far south on your page, as possible.
view sourceprint?

1<?php
2 $time = explode(" ",microtime());
3 $pagefinish = $time[0] + $time[1];
4 $pageload = $pagefinish - $pagestart;
5 print "Loaded in $pageload seconds.";
6?>
More PHP Tips you can view
 
Back
Top