Guest User

Untitled

a guest
Sep 25th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <html>
  2. <body>
  3. <form action = "dummy.php" method="Post">
  4. <input type = "text" name = "b_id1"/><br/><br/>
  5. <input type = "text" name = "b_id2"/><br/><br/>
  6. <input type = "text" name = "amount"/><br/><br/>
  7. <input type = "text" name = "Type"/><br/><br/>
  8. <input type = "submit" name = "submit"/><br/><br/>
  9. </body>
  10. </form>
  11.  
  12. <?php
  13. $servername = "localhost";
  14. $username = "root";
  15. $password = "";
  16. $dbname="rise";
  17. // Create connection
  18. $conn = mysqli_connect($servername, $username, $password);
  19.  
  20. // Check connection
  21. if (!$conn) {
  22. die("Connection failed: " . mysqli_connect_error());
  23. }
  24.  
  25. mysqli_select_db($conn,$dbname)
  26. or die("Unable to select database.");
  27. if(isset($_POST['submit']))
  28. {
  29. $acc_1 = $_POST['b_id1'];
  30. $acc_2 = $_POST['b_id2'];
  31. $amt = $_POST['amount'];
  32. $type = $_POST['Type'];
  33. //$acc_1 = 1;
  34. //$acc_2 = 2;
  35.  
  36. //$amt = 2000;
  37. //$type = 2;
  38. $flag = 0;
  39. $query1 = mysqli_query($conn,"SELECT Balance FROM accounts_info WHERE b_id = $acc_1 AND Type = $type");
  40. while ($item = mysqli_fetch_assoc($conn,$query1))
  41. {
  42. $sender_balance = $item['Balance'];
  43. if($sender_balance < $amt || $type == 3)
  44. {
  45. echo "Error";
  46. }
  47. else
  48. if($sender_balance-$amt<=10000)
  49. {
  50. echo "insufficient fund";
  51. }
  52. else
  53. {
  54. $flag = 1;
  55. $acc_1_balance = $sender_balance - $amt;
  56. $query1 = mysqli_query($conn,"UPDATE accounts_info SET Balance = $acc_1_balance WHERE b_id = $acc_1 AND Type = $type");
  57. echo "Transaction Succesful";
  58. $query2 = mysqli_query($conn,"SELECT Balance FROM accounts_info WHERE b_id = $acc_2 AND Type = $type");
  59. while ($itemf = mysqli_fetch_assoc($conn,$query2))
  60. {
  61.  
  62. $receiver_balance = $itemf['Balance'];
  63. $acc_2_balance = $receiver_balance + $amt;
  64. $query2 = mysqli_query($conn,"UPDATE accounts_info SET Balance = $acc_2_balance WHERE b_id = $acc_2 AND Type = $type");
  65. }
  66.  
  67. }
  68. }
  69.  
  70. }
  71. ?>
  72. </html>
Add Comment
Please, Sign In to add comment