Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <form action = "dummy.php" method="Post">
- <input type = "text" name = "b_id1"/><br/><br/>
- <input type = "text" name = "b_id2"/><br/><br/>
- <input type = "text" name = "amount"/><br/><br/>
- <input type = "text" name = "Type"/><br/><br/>
- <input type = "submit" name = "submit"/><br/><br/>
- </body>
- </form>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname="rise";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- mysqli_select_db($conn,$dbname)
- or die("Unable to select database.");
- if(isset($_POST['submit']))
- {
- $acc_1 = $_POST['b_id1'];
- $acc_2 = $_POST['b_id2'];
- $amt = $_POST['amount'];
- $type = $_POST['Type'];
- //$acc_1 = 1;
- //$acc_2 = 2;
- //$amt = 2000;
- //$type = 2;
- $flag = 0;
- $query1 = mysqli_query($conn,"SELECT Balance FROM accounts_info WHERE b_id = $acc_1 AND Type = $type");
- while ($item = mysqli_fetch_assoc($conn,$query1))
- {
- $sender_balance = $item['Balance'];
- if($sender_balance < $amt || $type == 3)
- {
- echo "Error";
- }
- else
- if($sender_balance-$amt<=10000)
- {
- echo "insufficient fund";
- }
- else
- {
- $flag = 1;
- $acc_1_balance = $sender_balance - $amt;
- $query1 = mysqli_query($conn,"UPDATE accounts_info SET Balance = $acc_1_balance WHERE b_id = $acc_1 AND Type = $type");
- echo "Transaction Succesful";
- $query2 = mysqli_query($conn,"SELECT Balance FROM accounts_info WHERE b_id = $acc_2 AND Type = $type");
- while ($itemf = mysqli_fetch_assoc($conn,$query2))
- {
- $receiver_balance = $itemf['Balance'];
- $acc_2_balance = $receiver_balance + $amt;
- $query2 = mysqli_query($conn,"UPDATE accounts_info SET Balance = $acc_2_balance WHERE b_id = $acc_2 AND Type = $type");
- }
- }
- }
- }
- ?>
- </html>
Add Comment
Please, Sign In to add comment