Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST['calc']))
  4. {
  5. $calc = $_POST['calc'];
  6. }
  7. else
  8. {
  9. $calc = "";
  10. }
  11.  
  12. if(isset($_POST['val1'], $_POST['val2']))
  13. {
  14. if ($_POST['val1'] == "" || $_POST['val2'] == "")
  15. {
  16. header("Location: ./temp.php");
  17. exit;
  18. }
  19. else
  20. {
  21. $val1 = $_POST['val1'];
  22. $val2 = $_POST['val2'];
  23. }
  24. }
  25.  
  26. switch ($calc)
  27. {
  28. case "add":
  29. $result = $val1 + $val2;
  30. break;
  31.  
  32. case "subtract":
  33. $result = $val1 - $val2;
  34. break;
  35.  
  36. case "multiply":
  37. $result = $val1 * $val2;
  38. break;
  39.  
  40. case "divide":
  41. $result = $val1 / $val2;
  42. break;
  43. }
  44.  
  45.  
  46. if(!isset($result))
  47. {
  48. echo "<p>Please fillout all the forums.</p>";
  49. }
  50. else
  51. {
  52. echo "<title>Calculation Result</title>";
  53. echo "<p>The result of the calculation is: $result</p>";
  54. echo "<p><a href=\"temp.php\" target=\"_self\">Do Another</a></p>";
  55. }
  56. ?>
  57.  
  58.  
  59. <html>
  60. <head>
  61. <title>Calculator</title>
  62. </head>
  63. <body>
  64. <form method="post" action="temp.php">
  65. <p>Value 1: <input type="text" name="val1" size="10"></p>
  66. <p>Value 2: <input type="text" name="val2" size="10"></p>
  67. <p>Calculation:<br>
  68. <input type="radio" name="calc" value="add"> add<br>
  69. <input type="radio" name="calc" value="subtract"> subtract<br>
  70. <input type="radio" name="calc" value="multiply"> multiply<br>
  71. <input type="radio" name="calc" value="divide"> divide</p>
  72. <p><input type="submit" name="submit" value="Calculate"></p>
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement