SHARE
TWEET

Untitled

a guest Jan 15th, 2020 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <?php
  3.    
  4.     if(isset($_POST['submit'])) {        
  5.         $total = 0;
  6.  
  7.         if($_POST['operasi'] == "*" || $_POST['oprasi'] == "/") {
  8.             $total = 1;
  9.         }
  10.  
  11.         $total_field_diisi = 0;
  12.         $operasi = $_POST['operasi'];        
  13.         foreach($_POST['input'] as $input) {                          
  14.             if(isset($input['check'])) {
  15.                 if($operasi == "+") {
  16.                     $total += $input['number'];
  17.                 } else if($operasi == "-") {
  18.                     $total -= $input['number'];
  19.                 } else if($operasi == "/") {
  20.                     $total /= $input['number'];
  21.                 } else if($operasi == "*") {
  22.                     $total *= $input['number'];
  23.                 } else {
  24.                     $total = false;
  25.                     break;
  26.                 }
  27.                 $total_field_diisi ++;
  28.             }
  29.         }
  30.  
  31.         if($total_field_diisi <= 1) {
  32.             $total = false;
  33.         }
  34.  
  35.  
  36.  
  37.     }
  38.  
  39. ?>
  40.  
  41.  
  42. <form action="" method="post">
  43.     <div class="form-group">
  44.         <input type="number" name="input[0][number]" placeholder="Number 1" id=""> <input type="checkbox" name="input[0][check]" id="">
  45.         <input type="number" name="input[1][number]" placeholder="Number 2" id=""> <input type="checkbox" name="input[1][check]" id="">
  46.         <input type="number" name="input[2][number]" placeholder="Number 3" id=""> <input type="checkbox" name="input[2][check]" id="">
  47.         <input type="text" name="operasi" id="" placeholder="operasi (+,-,/,*)">
  48.         <br>
  49.         <?php
  50.        
  51.             if(isset($total)) {
  52.                 if(!$total) {
  53.                     echo "Error";
  54.                 } else {
  55.                     echo "Total: " . $total . "<br/>";
  56.                 }
  57.             }
  58.  
  59.         ?>
  60.         <button type="submit" name="submit">Kirim</button>
  61.     </div>
  62. </form>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top