Can anyone show me how to do this?
I'm using a script out of Julie C. Meloni's book:
<?
if (ereg !=("^[0-9]+[.]?[0-9]*$", $val1)) {
header("Location:http://localhost/calculate_form.html");
exit;
if (ereg !=("^[0-9]+[.]?[0-9]*$", $val2)) {
header("Location:http://localhost/calculate_form.html");
exit;
if (($val1 == "") || ($val2 == "") || ($calc =="")) {
header("Location:http://localhost/calculate_form.html");
exit;
}
if ($calc == "add") {
$result = $val1 + $val2;
} else if ($calc == "subtract") {
$result = $val1 - $val2;
} else if ($calc == "multiply") {
$result = $val1 * $val2;
} else if ($calc == "divide") {
$result = $val1 / $val2;
}
?>
<HTML>
<HEAD>
<TITLE>Calculation Result</TITLE>
</HEAD>
<BODY>
<P>The result of your calculation is: <? echo
"$result"; ?></p>
</BODY>
</HTML>
Now, as you'll see, if you fail to complete one of the fields or click
one of
the radio buttons, the form is returned. Which is fine in so far as it
goes.
But the script will attempt to perform calculations on non numeric
fields and
I also want it to return the form if anyone puts in a non numeric value.
I think I need some ereg something like:
(ereg("^[0-9]+[.]?[0-9]*$", $i, $p))
but I've absolutely no idea how to do it.
If someone could show me, I'd be able to re-write a lot of my old C++
stuff in
PHP and I'd have a fair idea how to do functions in PHP.
Many thanks.
--
******************************************************************************
Marx: "Why do Anarchists only drink herbal tea?"
Proudhon: "Because all proper tea is theft."
******************************************************************************
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]