-
Notifications
You must be signed in to change notification settings - Fork 0
/
transfer.php
46 lines (37 loc) · 1.3 KB
/
transfer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
$mysqli = new mysqli("localhost", "root", "", "customerdb");
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
$fromAccount = $_POST['fromAccount'];
$toAccount = $_POST['toAccount'];
$amount = $_POST['amount'];
$query = "SELECT balance FROM customerinfo WHERE account_no = ?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("s", $fromAccount);
$stmt->execute();
$stmt->bind_result($senderBalance);
$stmt->fetch();
$stmt->close();
if ($senderBalance < $amount) {
echo "Insufficient balance.";
} else {
$query = "UPDATE customerinfo SET balance = balance - ? WHERE account_no = ?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("ds", $amount, $fromAccount);
$stmt->execute();
$stmt->close();
$query = "UPDATE customerinfo SET balance = balance + ? WHERE account_no = ?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("ds", $amount, $toAccount);
$stmt->execute();
$stmt->close();
echo "Transaction successful.";
}
$query = "INSERT INTO transactions (sender_account_no, receiver_account_no, amount) VALUES (?, ?, ?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("ssd", $fromAccount, $toAccount, $amount);
$stmt->execute();
$stmt->close();
$mysqli->close();
?>