i made a form with 2 input buttons(for taking number inputs) and 4 radio buttons(add sub mul and divide) and one submit button(calculate) to make a simple calculator and wrote a php script which takes input values and and according to the button selected do the operation but when i run this in browser and give values , select the required button it gives a list of errors about unused radio buttons (like if i select sub then at all the rest add mul and divide buttons it gives error) and in the last line shows correct answer, wha's this?

here is the code ofr script

<?php
if (($_POST[vall] == "") || ($_POST[val2] == "") || ($_POST[calc] =="")) 
{ header("Location: http://127.0.0.1/calculate_form.html");
exit;
 } 
if ($_POST[calc] == "add") {
   $result = $_POST[vall] + $_POST[val2];
}
 else if ($_POST[calc] == "subtract") { $result = $_POST[vall] - $_POST[val2]; }
 else if ($_POST[calc] == "multiply") { $result = $_POST[vall] * $_POST[val2]; } 
else if ($_POST[calc] == "divide") { $result = $_POST[vall] / $_POST[val2]; } 

?>
<HTML>
<HEAD>
<TITLE>Calculation Result</TITLE>
</HEAD>
<BODY>
<P>The result of the calculation is: <? echo "$result"; ?></P>
</BODY>
</HTML>

------------------------------------------------------------------
this one for form

<HTML>
<HEAD>
<TITLE>Calculation Form</TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST" ACTION="calculate.php">
<P>Value 1: <INPUT TYPE="text" NAME="vall" SIZE=10></P>
<P>Value 2: <INPUT TYPE="text" NAME="val2" SIZE=10></P>
<P>Calculation:<br>
<INPUT TYPE="radio" NAME="calc" VALUE="add"> add<br>
<INPUT TYPE="radio" NAME="calc" VALUE="subtract"> subtract<br>
<INPUT TYPE="radio" NAME="calc" VALUE="multiply"> multiply<br>
<INPUT TYPE="radio" NAME="calc" VALUE="divide"> divide</P>

<P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></P>
</FORM> </BODY> </HTML>

-----------------------------------------------------
and this one the error list
Notice: Use of undefined constant vall - assumed 'vall' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 2

Notice: Use of undefined constant val2 - assumed 'val2' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 2

Notice: Use of undefined constant calc - assumed 'calc' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 2

Notice: Use of undefined constant calc - assumed 'calc' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 6

Notice: Use of undefined constant vall - assumed 'vall' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 7

Notice: Use of undefined constant val2 - assumed 'val2' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 7

The result of the calculation is: 3
---------------------------------------------------------------
if any one could help me :( i dont want this error list before the answer

Please post your code.

Notices are not errors. You can get rid of notices by initializing a variable before using it.

yeah, 'vall' isn't a constant - you need to change it to $vall and declare it before.

thanx it's done by simply putting val in double quotes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.