I want to add,subtract,mu ltiply and divide two nos in a form for which i have 2 textboxes and for displaying o/p there is another textbox.there is 4 submit buttons which represent + - * /. after that i want to go next page that is in form action and after that the first page text box will display the result for a particular operation.
I have already written the code of this 2 pages.
1st page code:
2nd page code
what is the problem in this code?kindly help
I have already written the code of this 2 pages.
1st page code:
Code:
<form action="http://bytes.com/next.php" method="post" enctype="multipart/formdata">
1st No:<input type="text" name="n" id="t1"><br>
2nd No:<input type="text"name="n1" id="t2"><br> <input type="submit" name="butt" id="b1" value="+"> <input type="submit" name="butt" id="b2" value="-"> <input type="submit" name="butt" id="b3" value="*"> <input type="submit" name="butt" id="b4" value="/"><br>
Result is<input type="text" name="r" id="t3" value="<?php if(isset($_SESSION['b'])){echo $_SESSION['b'];}?>"> </form>
Code:
<?php
session_start();
$n=$_REQUEST['n'];
$_SESSION['n2']=$n;
$n1=$_REQUEST['n1'];
$_SESSION['n3']=$n1;
$butt=$_REQUEST['butt'];
if($butt=='+')
{
$res=$n+$n1;
$_SESSION['b']=$res;
}
else if($butt=='-')
{
$res=$n-$n1;
$_SESSION['b']=$res;
}
else if($butt=='*')
{
$res=$n*$n1;
$_SESSION['b']=$res;
}
else if($butt=='/')
{
$res=$n/$n1;
$_SESSION['b']=$res;
}
else
{
echo "enter number";
}
echo "<script>window.location.href='form1.php'</script>";
?>