hi
this is deepak, just beggner of learning php, facing some problem, if anyone could help me out, i will be thankful to him. when i run this code it will so me undefined variable as : calc , val1, and val2, which i have already declared in my html file.
my html code:
[HTML]
<html>
<head>
<title>Calculation form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</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><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="Calulate"></P>
</form>
</body>
</html>
[/HTML]
my php code:
[PHP]
<?php
$val1 = $_POST['val1'], $val2 = $_POST['val2'], $calc= &_POST['calc'];
if(($val1 == "") || ($val2 == "") || ($calc == "")){
header("Location: http://localhost/mySite/calculate_form.html");
exit;
}
if ($calc == "add"){
$result = $val1 + $val2;
} else if ($calc == "substruct"){
$result = $val1 - $val2;
} else if ($calc == "multiply"){
$result = $val1 * $val2;
} else if ($calc == "divide"){
$result = $val1 / $val2;
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<P> The result of the claculation is: <? echo "$result"; ?> </P>
</body>
</html>
[/PHP]