-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddBank.php
More file actions
executable file
·84 lines (71 loc) · 2.47 KB
/
addBank.php
File metadata and controls
executable file
·84 lines (71 loc) · 2.47 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
<?php
$conn = require __DIR__ . "/database.php";
session_start();
if (!isset($_SESSION["email"])) {
// Redirect to the login page if the user is not logged in
header('Location: index.php');
exit();
}
$email = mysqli_real_escape_string($conn, $_SESSION['email']);
$query = "SELECT * FROM account WHERE email='$email'";
$result = mysqli_query($conn, $query);
if ($row = mysqli_fetch_assoc($result)) {
$name = $row['userName'];
$password = $row['password'];
$phone = $row['phoneNum'];
$role = $row['role'];
} else {
// Handle case where email is not found in the database
$name = '';
$password = '';
$phone = '';
$role = '';
}
if (isset($_POST['add_account'])) {
$accountNumber = mysqli_real_escape_string($conn, $_POST['accountNumber']);
$branch = mysqli_real_escape_string($conn, $_POST['branch']);
$bank = mysqli_real_escape_string($conn, $_POST['bank']);
$owner = mysqli_real_escape_string($conn, $_POST['owner']);
$gold = mysqli_real_escape_string($conn, $_POST['gold']);
$address = mysqli_real_escape_string($conn, $_POST['address']);
// Check if $gold is not set or empty, and set it to an empty string
if (!isset($gold) || empty($gold)) {
$gold = "";
}
// Check if $address is not set or empty, and set it to an empty string
if (!isset($address) || empty($address)) {
$address = "";
}
$stmt = $conn->prepare("insert into bankaccount(accountNumber, branchNumber, bankName, owner, goldNumber, address) values(?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssss", $accountNumber, $branch, $bank, $owner, $gold, $address);
try {
$execval = $stmt->execute();
if ($execval) {
$res = [
'status' => 200,
'message' => ' החשבון הוקלט בהצלחה'
];
echo json_encode($res);
return;
}
} catch (mysqli_sql_exception $e) {
if ($e->getCode() === 1062) { // Error code for duplicate entry
$res = [
'status' => 500,
'message' => "כנראה שהחשבון כבר קיים במערכת"
];
echo json_encode($res);
return;
} else {
$res = [
'status' => 500,
'message' => 'החשבון לא הוקלט'
];
echo json_encode($res);
return;
}
}
echo $execval;
$stmt->close();
$conn->close();
}