SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- <html>
- <head>
- <meta charset="UTF-8">
- <title>PHP money transfers</title>
- </head>
- <body>
- <form action="teht5.php" method="post">
- <h2>Bank account withdrawals</h2>
- <?php if (isset($viesti)) echo '<p style="color:red">'.$viesti.'</p>'; ?>
- <table border="0" cellspacing="0" cellpadding="3">
- <tr>
- <td>withdrawal amount</td>
- <td><input type="text" name="withdrawal" value="" /></td>
- </tr>
- <tr>
- <td>Withdraw from</td>
- <td><input type="text" name="accFirst" value="" /></td>
- </tr>
- <tr>
- <td>Deposit to</td>
- <td><input type="text" name="accSecond" value="" /></td>
- </tr>
- </table>
- <br />
- <input type="submit" name="transfer" value="Transfer money" />
- <input type="submit" name="stop" value="Reset" />
- <?php
- session_start();
- class BankAccount{
- private $accountNumber;
- private $totalBalance;
- public function deposit($amount){
- $this->totalBalance += $amount;
- }
- public function withdraw($amount){
- if($amount > $this->totalBalance)
- die('Not enough money to withdraw');
- $this->totalBalance -= $amount;
- }
- public function getBalance(){
- return $this->totalBalance;
- }
- public function getAccountNumber(){
- return $this->accountNumber;
- }
- public function setAccountNumber($accountNumber){
- $this->accountNumber = $accountNumber;
- }
- }
- $acc1 = new BankAccount();
- $acc2 = new BankAccount();
- $acc1->setAccountNumber(13467);
- $acc1->deposit(7500);
- $acc2->setAccountNumber(23456);
- $acc2->deposit(600);
- $accFirst = intval($_POST['accFirst']);
- $withdrawal = intval($_POST['withdrawal']);
- $accSecond = intval($_POST['accSecond']);
- //HOW TO STOP MY PROGRAM ON RESETTING THESE VALUES AFTER EVERY TRANSFER
- if (isset($_POST['transfer'])){
- if ($acc1->getAccountNumber() == $accFirst && $acc2->getAccountNumber() == $accSecond ){
- $acc1->withdraw($withdrawal);
- $acc2->deposit($withdrawal);
- }else if ($acc1->getAccountNumber() == $accSecond && $acc2->getAccountNumber() == $accFirst ){
- $acc2->withdraw($withdrawal);
- $acc1->deposit($withdrawal);
- }
- if (isset($_POST['stop'])){
- session_destroy();
- echo "All session variables are now removed, and the session is destroyed.";
- }
- }
- ?>
- <p><strong>First bank account: </strong></p>
- <ul>
- <li><p><?php echo sprintf("Account: %s<br/>",$acc1->getAccountNumber()); ?></p></li>
- <li><p><?php echo sprintf("Balance: %0.2f<br/>", $acc1->getBalance());?></p></li>
- </ul>
- <p><strong>Second bank account: </strong></p>
- <ul>
- <li><p><?php echo sprintf("Account: %s<br/>",$acc2->getAccountNumber());?></p></li>
- <li><p><?php echo sprintf("Balance: %0.2f<br/>", $acc2->getBalance()); ?></p></li>
- </ul>
- </form>
- </body>
- </html>
RAW Paste Data

