Advertisement
Guest User

Untitled

a guest
May 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Maks
  5. * Date: 25.05.2016
  6. * Time: 8:00
  7. */
  8.  
  9. session_start();
  10.  
  11. $first_argument = $_POST["first_argument"];
  12. $second_argument = $_POST["second_argument"];
  13. $result = 0;
  14. $action = "";
  15.  
  16. if (isset($_POST["plus"])) {
  17. $action = "+";
  18. $result = $first_argument + $second_argument;
  19. }
  20. elseif (isset($_POST["minus"])) {
  21. $action = "-";
  22. $result = $first_argument - $second_argument;
  23. }
  24. elseif (isset($_POST["multiply"])) {
  25. $action = "*";
  26. $result = $first_argument * $second_argument;
  27. }
  28. elseif (isset($_POST["divide"])) {
  29. $action = "/";
  30. $result = $first_argument / $second_argument;
  31. }
  32.  
  33. $_SESSION["result"] = $result;
  34. ?>
  35.  
  36. <form action="index2.php" method="post" name="calculator">
  37. <input type = "text" name="first_argument" style="width:100px;">
  38. <?php echo $action ?>
  39. <input type = "text" name="second_argument" style="width:100px;">
  40. =
  41. <?php echo $result; ?>
  42. <br>
  43. <input type="submit" value="+" name="plus">
  44. <input type="submit" value="-" name="minus">
  45. <input type="submit" value="*" name="multiply">
  46. <input type="submit" value="/" name="divide">
  47. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement