Re: how do I do this, please?

From: Date: Fri, 19 Jan 2001 01:54:21 +0000
Subject: Re: how do I do this, please?
Groups: php.general 
Request: Send a blank email to php-general+get-35543@lists.php.net to get a copy of this message
Thanks Richard: I finally got it. I'm *really* rusty 'cos I went completely code blind and struggled for a day with a silly syntax error! This works just fine: <? if ((!ereg("^[0-9]+[.]?[0-9]*$", $val1))||(!ereg("^[0-9]+[.]?[0-9]*$", $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 the calculation is: <? echo "$result"; ?></p> </BODY> </HTML> And, for anyone else, it's a simple (but not for me, as it turned out!) ellaboration on the code in Julie Meloni's PHP fast&easy book to allow for error checking if a non-numerical value is entered. -- ****************************************************************************** Marx: "Why do Anarchists only drink herbal tea?" Proudhon: "Because all proper tea is theft." ******************************************************************************

« previous php.general (#35543) next »