problem in value printing in a textbox which is in another page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amrita sengupta
    New Member
    • Oct 2014
    • 1

    problem in value printing in a textbox which is in another page

    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:

    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>
    2nd page code

    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>";
    
    
    ?>
    what is the problem in this code?kindly help
    Last edited by Rabbit; Oct 13 '14, 06:00 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...