CT php class – 28-10-2015

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PHP-28-10-2015</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </head>
  <body>
    <div class="container">
        <div class="col-md-6 col-md-offset-3">
            <form action='action.php' method="post">
              <div class="form-group">
                <label for="exampleInputEmail1">Email address</label>
                <input type="number" class="form-control" id="exampleInputEmail1" placeholder="num1" name="num1">
              </div>
              <div class="form-group">
                <label for="exampleInputPassword1">Password</label>
                <input type="number" name="num2" class="form-control" id="exampleInputPassword1" placeholder="num2">
              </div>
<!--
              <div class="form-group">
                <label for="exampleInputFile">File input</label>
                <input type="file" id="exampleInputFile">
                <p class="help-block">Example block-level help text here.</p>
              </div>
              <div class="checkbox">
                <label>
                  <input type="checkbox"> Check me out
                </label>
              </div>
-->
              <button type="submit" class="btn btn-default">Submit</button>
            </form>    
        </div>
    </div>

    
  </body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>page2</title>
</head>
<body>
       <?php 
            error_reporting(0);
            $num1 = $_POST['num1'];
            $num2 = $_POST['num2'];

            session_start();
            $_SESSION["a"] = $num1;
            $_SESSION["b"] = $num2;

            echo 'Inserted value is '. $num1 . 'and '. $num2 .'<br>';
            $add = $_POST['add'];
            $sub = $_POST['sub'];
            $mul = $_POST['mul'];
            $div = $_POST['div'];

//    if(isset($add)){
//        echo $_SESSION["a"]+$_SESSION["b"];
//        
//    }
//    elseif(isset($sub)){
//        echo $_SESSION["a"] - $_SESSION["b"];
//        
//    }
//    elseif(isset($mul)){
//        echo $_SESSION["a"] * $_SESSION["b"];
//        
//    }
//    elseif(isset($div)){
//        echo $_SESSION["a"] / $_SESSION["b"];
//        
//    }

    if(isset($add)){
        echo $num1+$num2;
        
    }
    elseif(isset($sub)){
        echo $num1-$num2;;
        
    }
    elseif(isset($mul)){
        echo $num1*$num2;;
        
    }
    elseif(isset($div)){
        echo $num1/$num2;;
        
    }


        ?>     

       <form action="" method="post">
          <input type="hidden" value="<?php echo $num1?>" name="num1">
          <input type="hidden" value="<?php echo $num2?>" name="num2">
           <input type="submit" name="add" value='+'>
           <input type="submit" name="sub" value='-'>
           <input type="submit" name="mul" value='x'>
           <input type="submit" name="div" value='/'>
       </form>
      

</body>
</html>