Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. if(isset($_POST['submit']))
  6. {
  7.     define('GENERAL_PRICE', 5.00);
  8.     define('VIP_PRICE', 20.00);
  9.  
  10.     if(isset($_POST['general']) && isset($_POST['vip']))
  11.     {
  12.         $general = $_POST['general'];
  13.         $vip = $_POST['vip'];
  14.  
  15.         //set discount
  16.         if($general + $vip >= 5)
  17.         {
  18.             $discount = 0.75;
  19.         } else {
  20.             $discount = 0;
  21.         }
  22.  
  23.         // calculate cost
  24.         $cost = ((GENERAL_PRICE  * $discount) * $general) + ((VIP_PRICE * $discount) * $vip);
  25.         echo $cost;
  26.  
  27.     } else {
  28.         $error = 'You must fill out the number of general and VIP tickets';
  29.         echo $error;
  30.     }
  31. }
  32. ?>
  33.  
  34. <form action="demo.php" method="post">
  35.     <input type="text" name="general" placeholder="General">
  36.     <br/><br/>
  37.     <input type="text" name="vip" placeholder="VIP">
  38.     <br/><br/>
  39.     <button type="submit" name="submit">Calculate</button>
  40. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement