Advertisement
MilaDimitrovaa

result.php

Nov 29th, 2021
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     echo "<pre>";
  4.     echo var_dump($_GET);
  5.     echo "</pre>";
  6.  
  7.     if (isset($_GET["n1"]) && isset($_GET["n2"]) && isset($_GET["op"])) {
  8.         $n1 = $_GET["n1"];
  9.         $n2 = $_GET["n2"];
  10.         $op = $_GET["op"];
  11.  
  12.         if(is_numeric($n1) && is_numeric($n2)) {
  13.             if ($op == "add") {
  14.                 $r = $n1 + $n2;
  15.                 $_SESSION["result"] = $r;
  16.             } else if ($op == "sub") {
  17.                 $r = $n1 - $n2;
  18.                 $_SESSION["result"] = $r;
  19.             } else if ($op == "mul") {
  20.                 $r = $n1 * $n2;
  21.                 $_SESSION["result"] = $r;
  22.             } else if ($op == "div") {
  23.                 if($n2 == 0) {
  24.                     $_SESSION["error"] = "You can't divided by zero.";
  25.                 } else {
  26.                     $r = $n1 / $n2;
  27.                     $_SESSION["result"] = $r;
  28.                 }
  29.             } else if ($op == "") {
  30.                 $_SESSION["error"] = "Please select operation";
  31.             }
  32.         } else {
  33.             $_SESSION["error"] = "Please input only numbers!";
  34.         }
  35.     } else {
  36.         $_SESSION["error"] = "You have a mistake on a HTML file";
  37.     }
  38.  
  39.     header("location: index.php");
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement