daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.  <head>
  3.   <meta charset="UTF-8">
  4.   <title>PHP money transfers</title>
  5.  </head>
  6.  <body>
  7.  
  8.     <form action="teht5.php" method="post">
  9.     <h2>Bank account withdrawals</h2>
  10.  
  11.     <?php if (isset($viesti)) echo '<p style="color:red">'.$viesti.'</p>'; ?>
  12.    
  13.     <table border="0" cellspacing="0" cellpadding="3">
  14.         <tr>
  15.             <td>withdrawal amount</td>
  16.             <td><input type="text" name="withdrawal" value="" /></td>
  17.         </tr>
  18.         <tr>
  19.             <td>Withdraw from</td>
  20.             <td><input type="text" name="accFirst" value="" /></td>
  21.         </tr>
  22.         <tr>
  23.             <td>Deposit to</td>
  24.             <td><input type="text" name="accSecond" value="" /></td>
  25.         </tr>
  26.     </table>
  27.  
  28.     <br />
  29.    
  30.     <input type="submit" name="transfer" value="Transfer money" />
  31.     <input type="submit" name="stop" value="Reset" />
  32.     <?php
  33.     session_start();
  34.     class BankAccount{
  35.        
  36.         private $accountNumber;
  37.        
  38.         private $totalBalance;
  39.      
  40.         public function deposit($amount){
  41.             $this->totalBalance += $amount;
  42.         }
  43.      
  44.        
  45.         public function withdraw($amount){
  46.             if($amount > $this->totalBalance)
  47.                 die('Not enough money to withdraw');
  48.      
  49.             $this->totalBalance -= $amount;
  50.         }
  51.      
  52.        
  53.         public function getBalance(){
  54.                
  55.             return $this->totalBalance;
  56.         }
  57.      
  58.         public function getAccountNumber(){
  59.             return $this->accountNumber;
  60.         }
  61.      
  62.         public function setAccountNumber($accountNumber){
  63.             $this->accountNumber = $accountNumber;
  64.      
  65.         }
  66.     }
  67.    
  68.     $acc1 = new BankAccount();
  69.     $acc2 = new BankAccount();
  70.     $acc1->setAccountNumber(13467);
  71.     $acc1->deposit(7500);
  72.  
  73.     $acc2->setAccountNumber(23456);
  74.     $acc2->deposit(600);
  75.  
  76.     $accFirst = intval($_POST['accFirst']);
  77.     $withdrawal = intval($_POST['withdrawal']);
  78.     $accSecond = intval($_POST['accSecond']);
  79.      
  80.     //HOW TO STOP MY PROGRAM ON RESETTING THESE VALUES AFTER EVERY TRANSFER
  81.     if (isset($_POST['transfer'])){
  82.         if ($acc1->getAccountNumber() == $accFirst && $acc2->getAccountNumber() == $accSecond ){
  83.             $acc1->withdraw($withdrawal);
  84.             $acc2->deposit($withdrawal);
  85.         }else if ($acc1->getAccountNumber() == $accSecond && $acc2->getAccountNumber() == $accFirst ){
  86.             $acc2->withdraw($withdrawal);
  87.             $acc1->deposit($withdrawal);    
  88.        
  89.     }
  90.     if (isset($_POST['stop'])){
  91.             session_destroy();
  92.             echo "All session variables are now removed, and the session is destroyed.";
  93.         }    
  94.    
  95.     }    
  96.     ?>
  97.     <p><strong>First bank account: </strong></p>
  98.     <ul>
  99.       <li><p><?php echo sprintf("Account: %s<br/>",$acc1->getAccountNumber()); ?></p></li>
  100.       <li><p><?php echo sprintf("Balance: %0.2f<br/>", $acc1->getBalance());?></p></li>
  101.     </ul>
  102.    
  103.     <p><strong>Second bank account: </strong></p>
  104.     <ul>
  105.       <li><p><?php echo sprintf("Account: %s<br/>",$acc2->getAccountNumber());?></p></li>
  106.       <li><p><?php echo sprintf("Balance: %0.2f<br/>", $acc2->getBalance()); ?></p></li>
  107.     </ul>
  108.     </form>
  109.  
  110. </body>
  111. </html>
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top