-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDBUpdate.php
73 lines (54 loc) · 2.1 KB
/
DBUpdate.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php session_start(); ?>
<?php
$senderName = $_GET["senderName"];
$senderBalance = $_GET["senderBalance"];
$receiverName = $_GET["receiverName"];
$amountToBeSent= $_GET["amountToBeSent"];
$date = new DateTime();
$timeStamp= date('D, d M Y H:i:s', $date->getTimestamp());
// Create connection
$servername = "localhost:3306";
$username = "root";
$password = "";
$db = "bank";
// Create connection
$conn = mysqli_connect($servername, $username, $password,$db);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "UPDATE customer SET balance =".$senderBalance." where name=".$senderName;
$sqlUpdate ="UPDATE customer SET balance ='".$senderBalance."' where name='".$senderName."';";
if (mysqli_query($conn, $sqlUpdate)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
$sqlInsert ="INSERT INTO transactionhistory (customerName, transactionAmount, timestamp, sendReceive) VALUES ('".$senderName."','".$amountToBeSent."','".$timeStamp."','send');";
if (mysqli_query($conn, $sqlInsert)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
$sql =$conn -> query("select Balance from customer where name='".$receiverName."';");
while($row = $sql->fetch_assoc()) {
$receiverBalance= $row["Balance"];
$receiverFinalBalance= $receiverBalance + $amountToBeSent;
$sqlNew ="UPDATE customer SET balance ='".$receiverFinalBalance."' where name='".$receiverName."';";
if (mysqli_query($conn, $sqlNew)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
$sqlInsert ="INSERT INTO transactionhistory (customerName, transactionAmount, timestamp, sendReceive) VALUES ('".$receiverName."','".$receiverFinalBalance."','".$timeStamp."','received');";
if (mysqli_query($conn, $sqlInsert)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
}
mysqli_close($conn);
?>
<script>
window.location="Customers.php";
</script>