-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccount.php
More file actions
144 lines (124 loc) · 5.39 KB
/
account.php
File metadata and controls
144 lines (124 loc) · 5.39 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
session_start();
error_reporting(E_ALL);
ini_set("display_errors", 1);
include_once 'dbconfig.php';
$db_name = 'keeping';
mysqli_select_db($conn, $db_name);
// 사용자의 user_id를 세션에서 가져옴
$user_id = $_SESSION['username'];
// 사용자가 폼을 통해 계좌 추가한 경우
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 폼으로부터 받은 계좌 정보
if (isset($_POST['addAccount'])) {
$account_num = $_POST['account_num'];
$bank_name = $_POST['bank_name'];
$balance = $_POST['balance'];
$deposit_and_withdrawal_status = $_POST['deposit_and_withdrawal_status'];
// 중복된 account_num 체크
$checkDuplicateQuery = "SELECT * FROM account WHERE account_number = '$account_num' AND a_user_id = '$user_id'";
$duplicateResult = $conn->query($checkDuplicateQuery);
if ($duplicateResult->num_rows > 0) {
echo "<script>alert('Account number already exists.')</script>";
} else {
// Map bank_name to a_bank_id
$bankIdMap = [
'NH' => 1,
'ShinHan' => 2,
'Shin' => 3,
'KB' => 4,
'SC' => 5,
'Kakaobank' => 6,
];
// Get a_bank_id based on the selected bank_name
$a_bank_id = isset($bankIdMap[$bank_name]) ? $bankIdMap[$bank_name] : null;
// 사용자의 계좌 정보를 추가하는 쿼리
$insertAccountQuery = "INSERT INTO account (account_number, balance, deposit_and_withdrawal_status, a_user_id, a_bank_id) VALUES ('$account_num', $balance, '$deposit_and_withdrawal_status', '$user_id', $a_bank_id)";
if ($conn->query($insertAccountQuery) === TRUE) {
echo "<script>alert('Account sucessfully added.')</script>";
} else {
echo "<script>alert('Account addition failed : ')</script>" . $conn->error;
}
}
}
// 폼으로부터 받은 삭제할 계좌 번호
if (isset($_POST['deleteAccount'])) {
$deleteAccountNum = $_POST['deleteAccountNum'];
// 사용자의 계좌 정보를 삭제하는 쿼리
$deleteAccountQuery = "DELETE FROM account WHERE account_number = '$deleteAccountNum' AND a_user_id = '$user_id'";
if ($conn->query($deleteAccountQuery) === TRUE) {
echo "<script>alert('Account successfully deleted')</script>";
} else {
echo "<script>alert('Account deletion failed : ')</script>" . $conn->error;
}
}
}
// 사용자의 계좌 정보를 가져오는 쿼리
$getAccountQuery = "SELECT a.*, b.bank_name, b.bank_img FROM account a JOIN bank b ON a.a_bank_id = b.bank_id WHERE a.a_user_id = '$user_id'";
$result1 = $conn->query($getAccountQuery);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="updateBalance.js"></script>
<link rel=stylesheet href='account.css' type='text/css'>
<link rel=stylesheet href='assets\navbar.css' type='text/css'>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>계좌 관리</title>
</head>
<body>
<span id='navbar'>
<?php include 'navbar.php'; ?>
</span>
<form method="post" action="" class="accountForm">
<h1>Account Management</h1>
<h2>Add Account</h2>
<input type="text" name="account_num" class="account_num" placeholder="account num"><br>
<select name="bank_name" class="bank_name">
<option value="NH">NH</option>
<option value="ShinHan">ShinHan</option>
<option value="Shin">Shin</option>
<option value="KB">KB</option>
<option value="SC">SC</option>
<option value="Kakaobank">Kakaobank</option>
</select><br>
<input type="text" name="balance" class="balance" placeholder="balance"><br>
<input type="text" name="deposit_and_withdrawal_status" class="deposit_and_withdrawal_status" placeholder="deposit_and_withdrawal_status"><br>
<br>
<input type="submit" name="addAccount" value="add account">
<h2>Account List</h2>
<?php
$result1 = $conn->query($getAccountQuery);
$totalBalance = 0;
while ($row1 = $result1->fetch_assoc()) {
echo "<div class='account-info'>";
echo "<p>";
$bankImage = $row1['bank_img'];
echo "<img src='$bankImage' alt='Bank Image'><br>";
echo "<p>";
echo $row1['bank_name'] . " ";
echo $row1['account_number'] . "<br>";
echo "Balance : " . $row1['balance'] . " ₩<br>";
echo "deposit_and_withdrawal_status " . ($row1['deposit_and_withdrawal_status'] == 1 ? "O" : "X") . "<br>";
echo "<br>";
// 계좌 금액을 총액에 더함
$totalBalance += $row1['balance'];
// 삭제 폼 추가
echo "<form method='post' action='' class='delete-form'>";
echo "<input type='hidden' name='deleteAccountNum' value='" . $row1['account_number'] . "'>";
echo "<input type='submit' name='deleteAccount' value='delete account'>";
echo "</form>";
echo "------------------------";
echo "</p>";
}
if ($result1->num_rows == 0) {
echo "NULL.";
}
// 총액 표시
echo "<p>Total Balance: " . $totalBalance . " ₩</p>";
?>
</form>
</body>
</html>