Advertisement
michaelyuen

Untitled

Aug 24th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('display_errors', 0);
  4.  
  5. if(isset($_POST['calculate'])) {
  6.  
  7.     $operator = $_POST['operator'];
  8.  
  9.     switch ($operator) {
  10.         case '+':
  11.                 $add1 = $_POST['firstValue'];
  12.                 $add2 = $_POST['lastValue'];
  13.                 $result = $add1 + $add2;
  14.                 break; // here
  15.  
  16.         case '-':
  17.                 $add1 = $_POST['firstValue'];
  18.                 $add2 = $_POST['lastValue'];
  19.                 $result = $add1 - $add2;
  20.                 break; // here
  21.         case '*':
  22.                 $add1 = $_POST['firstValue'];
  23.                 $add2 = $_POST['lastValue'];
  24.                 $result = $add1 * $add2;
  25.                 break; // here
  26.         case '/':
  27.                 $add1 = $_POST['firstValue'];
  28.                 $add2 = $_POST['lastValue'];
  29.                 $result = $add1 / $add2;
  30.                 break;
  31.  
  32.         default:
  33.                 echo "not accepted";
  34.                 break;
  35.     }
  36.  
  37.     if(empty($_POST['firstValue']) && empty($_POST['lastValue'])) { // here $_POST
  38.  
  39.              echo  "<script>alert('Please enter values')</script>";
  40.         }
  41.  
  42.         elseif (empty($_POST['firstValue'])) {// here $_POST
  43.            
  44.              echo  "<script>alert('Please enter first value')</script>";
  45.         }
  46.  
  47.         elseif (empty($_POST['lastValue'])) {// here $_POST
  48.            
  49.              echo  "<script>alert('Please enter second value')</script>";
  50.         }
  51.  
  52. }
  53.  
  54.  
  55. ?>
  56.  
  57.  
  58.  
  59.  
  60. <form action="" method="POST"> <!-- here method="POST" -->
  61.     <table style="border: groove #00FF99">
  62.         <tr>
  63.  
  64.         <td style="background-color: aqua; color: red; font-family: Arial;">Enter first number</td>
  65.         <td colspan="1"><input type="text" name="firstValue" style="color: red;"></td>
  66.  
  67.         <tr>
  68.             <td style="color:burlywood; font-family: Arial;">Select Operator</td>
  69.             <td>
  70.                 <select name="operator" style="width: 63px;">
  71.                     <option>+</option>
  72.                     <option>-</option>
  73.                     <option>*</option>
  74.                     <option>/</option>
  75.                 </select>
  76.             </td>
  77.         </tr>
  78.  
  79.         <tr>
  80.  
  81.         <td style="background-color: aqua; color: red; font-family: Arial;">Enter second number</td>
  82.         <td class="auto-style5"><input type="text" name="lastValue" style="color: red;"></td>
  83.  
  84.         </tr>
  85.  
  86.                 <tr>
  87.                     <td></td>
  88.                     <td><input type="submit" name="calculate" value="Calculate" style="color: wheat; background-color: rosybrown;">         </td>
  89.                 </tr>
  90.  
  91.                 <tr>
  92.                     <td style="background-color: aqua; color: red;">Output =</td>
  93.                     <td style="color: darkblue;"><?php echo $result; ?></td>
  94.                 </tr>
  95.  
  96.                 </tr>
  97.             </table>
  98.         </form>
  99.  
  100.    
  101.  
  102.  
  103.  
  104.  
  105. </body>
  106. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement