i am new to php and i reffred a book to get the below written code but when i run it it gives notices.
calculate_form.html ================>
Code: Select all
<HTML>
<HEAD>
<TITLE>Calculation Form</TITLE>
</HEAD>
<BODY>
<FORM METHOD="post" ACTION="calculate.php">
<P>Value 1: <INPUT TYPE="text" NAME="val1" 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>
calculate.php======================>
<HTML>
<HEAD>
<TITLE>Calculation Result</TITLE>
</HEAD>
<BODY>
<?
if (($_POST[val1] == "") || ($_POST[val2] == "")|| ($_POST[calc] =="")) {
header("Location: calculate_form.html");
exit;
}
if ($_POST[calc] == "add") {
$result = $_POST[val1] + $_POST[val2];
} else if ($_POST[calc] == "subtract") {
$result = $_POST[val1] - $_POST[val2];
} else if ($_POST[calc] == "multiply") {
$result = $_POST[val1] * $_POST[val2];
} else if ($_POST[calc] == "divide") {
$result = $_POST[val1] / $_POST[val2];
}
?>
<P>The result of the calculation is: <? echo "$result"; ?></P>
</BODY>
</HTML>
and when i access calculate.php from calculate_form.html i get the following notices in browser===========>
Notice: Use of undefined constant val1 - assumed 'val1' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\calculate.php on line 8
Notice: Use of undefined constant val2 - assumed 'val2' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\calculate.php on line 8
Notice: Use of undefined constant calc - assumed 'calc' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\calculate.php on line 8
Notice: Use of undefined constant calc - assumed 'calc' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\calculate.php on line 12
Notice: Use of undefined constant val1 - assumed 'val1' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\calculate.php on line 13
Notice: Use of undefined constant val2 - assumed 'val2' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\calculate.php on line 13
The result of the calculation is: 10
but the script works wel when i use $_POST['val1'] intead of $_POST[val1] can any one help me with this