silverglade Posted August 4, 2008 Share Posted August 4, 2008 hi, here is the error i get Notice: Undefined variable: val1 in D:\Inetpub\virtual\brendansite1\WWWROOT\calc.php on line 4 Invalid entry - please retry here is the form code <html><head> <title>Calculation Form</title> </head> <body> <form action="calc.php" method="post"> Value 1: <input type="text" name="val1" size="10"> Value 2: <input type="text" name="val2" size="10"> <br> Calculation: <br> <input type="radio" name="calc" value="add">Add <input type="radio" name="calc" value="sub">Subtract <input type="radio" name="calc" value="mul">Multiply <input type="radio" name="calc" value="div">Divide <br> <input type="submit" value="Calculate"> <input type="reset" value="Clear"> </form> </body></html> and here is the php code <html><head><title>Calculation Result</title></head> <body> <?php if( is_numeric($val1) && is_numeric($val2) ) { if($calc != null) { switch($calc) { case "add" : $result= $val1 + $val2; break; case "sub" : $result= $val1 - $val2; break; case "mul" : $result= $val1 * $val2; break; case "div" : $result= $val1 / $val2; break; } echo("Calculation result: $result"); } } else{ echo("Invalid entry - please retry"); } ?> </body></html> any help greatly appreciated, im lost on this one. thanks. derek Link to comment https://forums.phpfreaks.com/topic/118108-solved-cant-get-this-php-calculator-code-to-work/ Share on other sites More sharing options...
The Little Guy Posted August 4, 2008 Share Posted August 4, 2008 Well... What is it not doing? Link to comment https://forums.phpfreaks.com/topic/118108-solved-cant-get-this-php-calculator-code-to-work/#findComment-607638 Share on other sites More sharing options...
silverglade Posted August 4, 2008 Author Share Posted August 4, 2008 i get the following error when i try to execute it. Notice: Undefined variable: val1 in D:\Inetpub\virtual\brendansite1\WWWROOT\calc.php on line 4 Invalid entry - please retry Link to comment https://forums.phpfreaks.com/topic/118108-solved-cant-get-this-php-calculator-code-to-work/#findComment-607644 Share on other sites More sharing options...
The Little Guy Posted August 4, 2008 Share Posted August 4, 2008 OK, right before your "if statement" add this: $val1 = $_POST['val1']; $val2 = $_POST['val2']; $calc = $_POST['calc']; Link to comment https://forums.phpfreaks.com/topic/118108-solved-cant-get-this-php-calculator-code-to-work/#findComment-607653 Share on other sites More sharing options...
silverglade Posted August 4, 2008 Author Share Posted August 4, 2008 awesome that fixed it thank you very much!!!. DEREK ;D ;D Link to comment https://forums.phpfreaks.com/topic/118108-solved-cant-get-this-php-calculator-code-to-work/#findComment-607656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.