Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. <?php
  2. require_once'mysqlLogin.php';
  3.  
  4. $connection=new mysqli($db_hostname, $db_username,$db_password,$db_database);
  5. if ($connection->connect_error) die($connection->connect_error);
  6. $accountNum=$_COOKIE['cookie_account'];
  7. $query="SELECT*FROM bank WHERE accountNum=$accountNum";
  8. $result=$connection->query($query);
  9. if (!$result) die ($connection->error);
  10. $display=$result->fetch_array(MYSQLI_ASSOC);
  11.  
  12. //deposit
  13. if (isset($_POST['deposit'])){
  14.     $deposit=sanitizeString($_POST['deposit']);
  15.     if ($deposit<0){
  16.         die("deposit can't be lower than 0");
  17.     }
  18.     $newMoney=$display['money']+$deposit;
  19.     $query="BEGIN";
  20.     $connection->query($query);
  21.     $query="UPDATE bank SET money=$newMoney WHERE accountNum=$accountNum";
  22.     $connection->query($query);
  23.     $query="COMMIT";
  24.     $connection->query($query);
  25.     $_POST['deposit']=0; //if you deposited money and then refreshed it deposited it again
  26.     $_POST['withdraw']=NULL;
  27. }
  28.  
  29. if (isset($_POST['withdraw'])){
  30.     $withdraw=sanitizeString($_POST['withdraw']);
  31.     if ($withdraw<0){
  32.         die("withdraw can't be lower than 0");
  33.     }
  34.     $newMoney=$display['money']-$withdraw;
  35.     $query="BEGIN";
  36.     $connection->query($query);
  37.     $query="UPDATE bank SET money=$newMoney WHERE accountNum=$accountNum";
  38.     $connection->query($query);
  39.     $query="COMMIT";
  40.     $connection->query($query);
  41.     $_POST['withdraw']=0; //if you withdrew money and then refreshed it deposited it again
  42.     $_POST['deposit']=NULL;
  43. }
  44.  
  45. $query="SELECT*FROM bank WHERE accountNum=$accountNum";
  46. $result=$connection->query($query);
  47. if (!$result) die ($connection->error);
  48. $display=$result->fetch_array(MYSQLI_ASSOC);
  49. //display the name and everthing
  50. echo "Account Number: ".$display['accountNum']."<br>";
  51. echo "Name: ".$display['firstName']."<br>";
  52. echo "LastName: ".$display['lastName']."<br>";
  53. echo "Money: ".$display['money']."<br>";
  54.  
  55. echo <<<_END
  56. <html>
  57. <bod>
  58. <form method="post" action="accountManagment.php">
  59. <br>
  60. Deposit:
  61. <input type="number" name="deposit" value="FALSE">
  62. <br>
  63. Withdraw:
  64. <input type="number" name="withdraw" value="FALSE">
  65. <br>
  66. <input type="submit" name"submit" value="submit">
  67. _END;
  68.  
  69. $result->close();
  70. $connection->close();
  71.  
  72.  
  73. function sanitizeString($string)
  74. {//gets rid of some html signs
  75. return htmlentities(mysql_fix_string($string));
  76. }
  77.  
  78. function mysql_fix_string($string)
  79. {
  80. if (get_magic_quotes_gpc()) $string = stripslashes($string);
  81. return $string;
  82. }
  83.  
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement