how do I do this, please?

From: Date: Mon, 15 Jan 2001 18:28:31 +0000
Subject: how do I do this, please?
Groups: php.general 
Request: Send a blank email to php-general+get-34642@lists.php.net to get a copy of this message
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." ******************************************************************************

« previous php.general (#34642) next »