-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
55 lines (46 loc) · 2.33 KB
/
query.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
<?php
include_once "connection.php";
$sqlBank = "SELECT * FROM bank";
$bank = mysqli_query($conn, $sqlBank);
$sqlTransactions = "SELECT * FROM transactions";
$transactions = mysqli_query($conn, $sqlTransactions);
if(isset($_POST['btnCredit'])){
$amount = $_POST['txtAmount'];
$bankname = $_POST['bankName'];
$creditedFrom = $_POST['txtSummary'];
$date = DateTime::createFromFormat('d/m/Y', $_POST['dateCredit']);
$date = $date->format('Y-m-d');
// print_r($_POST);
$insertSql = "INSERT INTO transactions(typeoftransaction,transactionfrom,amount,summary,dateupdated) VALUES('Credit','$bankname','$amount','$creditedFrom','$date')";
// echo $insertSql;
$updateSql = "UPDATE bank SET $bankname=$bankname+$amount, dateupdated=NOW()";
// echo $updateSql;
$insertResult = mysqli_query($conn, $insertSql);
$updateResult = mysqli_query($conn, $updateSql);
$bank = mysqli_query($conn, $sqlBank);
$transactions = mysqli_query($conn, $sqlTransactions);
}
if(isset($_POST['btnDebit'])){
$amount = $_POST['txtAmount'];
$bankname = $_POST['bankName'];
$debitedTo = $_POST['txtSummary'];
$date = DateTime::createFromFormat('d/m/Y', $_POST['dateDebit']);
$date = $date->format('Y-m-d');
// print_r($_POST);
$insertSql = "INSERT INTO transactions(typeoftransaction,transactionfrom,amount,summary,dateupdated) VALUES('Debit','$bankname','$amount','$debitedTo','$date')";
// echo $insertSql;
$updateSql = "UPDATE bank SET $bankname=$bankname-$amount, dateupdated=NOW()";
// echo $updateSql;
$insertResult = mysqli_query($conn, $insertSql);
$updateResult = mysqli_query($conn, $updateSql);
$bank = mysqli_query($conn, $sqlBank);
$transactions = mysqli_query($conn, $sqlTransactions);
}
if(isset($_POST['btnSearch'])){
$txtSearch = $_POST['txtSearch'];
// var_dump($txtSearch);
$sqlTransactions = "SELECT * FROM transactions WHERE status LIKE '%$txtSearch%' OR typeoftransaction LIKE '%$txtSearch%' OR transactionfrom LIKE '%$txtSearch%'";
// var_dump($sqlTransactions);
$transactions = mysqli_query($conn, $sqlTransactions);
}
?>