-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_expense.php
263 lines (234 loc) · 12.3 KB
/
add_expense.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
include("session.php");
$update = false;
$del = false;
$expenseamount = "";
$expensedate = date("Y-m-d");
$expensecategory = "Entertainment";
if (isset($_POST['add'])) {
$expenseamount = $_POST['expenseamount'];
$expensedate = $_POST['expensedate'];
$expensecategory = $_POST['expensecategory'];
$expenses = "INSERT INTO expenses (user_id, expense,expensedate,expensecategory) VALUES ('$userid', '$expenseamount','$expensedate','$expensecategory')";
$result = mysqli_query($con, $expenses) or die("Something Went Wrong!");
header('location: add_expense.php');
}
if (isset($_POST['update'])) {
$id = $_GET['edit'];
$expenseamount = $_POST['expenseamount'];
$expensedate = $_POST['expensedate'];
$expensecategory = $_POST['expensecategory'];
$sql = "UPDATE expenses SET expense='$expenseamount', expensedate='$expensedate', expensecategory='$expensecategory' WHERE user_id='$userid' AND expense_id='$id'";
if (mysqli_query($con, $sql)) {
echo "Records were updated successfully.";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($con);
}
header('location: manage_expense.php');
}
if (isset($_POST['update'])) {
$id = $_GET['edit'];
$expenseamount = $_POST['expenseamount'];
$expensedate = $_POST['expensedate'];
$expensecategory = $_POST['expensecategory'];
$sql = "UPDATE expenses SET expense='$expenseamount', expensedate='$expensedate', expensecategory='$expensecategory' WHERE user_id='$userid' AND expense_id='$id'";
if (mysqli_query($con, $sql)) {
echo "Records were updated successfully.";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($con);
}
header('location: manage_expense.php');
}
if (isset($_POST['delete'])) {
$id = $_GET['delete'];
$expenseamount = $_POST['expenseamount'];
$expensedate = $_POST['expensedate'];
$expensecategory = $_POST['expensecategory'];
$sql = "DELETE FROM expenses WHERE user_id='$userid' AND expense_id='$id'";
if (mysqli_query($con, $sql)) {
echo "Records were updated successfully.";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($con);
}
header('location: manage_expense.php');
}
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$update = true;
$record = mysqli_query($con, "SELECT * FROM expenses WHERE user_id='$userid' AND expense_id=$id");
if (mysqli_num_rows($record) == 1) {
$n = mysqli_fetch_array($record);
$expenseamount = $n['expense'];
$expensedate = $n['expensedate'];
$expensecategory = $n['expensecategory'];
} else {
echo ("WARNING: AUTHORIZATION ERROR: Trying to Access Unauthorized data");
}
}
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$del = true;
$record = mysqli_query($con, "SELECT * FROM expenses WHERE user_id='$userid' AND expense_id=$id");
if (mysqli_num_rows($record) == 1) {
$n = mysqli_fetch_array($record);
$expenseamount = $n['expense'];
$expensedate = $n['expensedate'];
$expensecategory = $n['expensecategory'];
} else {
echo ("WARNING: AUTHORIZATION ERROR: Trying to Access Unauthorized data");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Expense Manager - Dashboard</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
<!-- Feather JS for Icons -->
<script src="js/feather.min.js"></script>
</head>
<body>
<div class="d-flex" id="wrapper">
<!-- Sidebar -->
<div class="border-right" id="sidebar-wrapper">
<div class="user">
<img class="img img-fluid rounded-circle" src="<?php echo $userprofile ?>" width="120">
<h5><?php echo $username ?></h5>
<p><?php echo $useremail ?></p>
</div>
<div class="sidebar-heading">Management</div>
<div class="list-group list-group-flush">
<a href="index.php" class="list-group-item list-group-item-action"><span data-feather="home"></span> Dashboard</a>
<a href="add_expense.php" class="list-group-item list-group-item-action sidebar-active"><span data-feather="plus-circle"></span> Add Expenses</a>
<a href="manage_expense.php" class="list-group-item list-group-item-action"><span data-feather="file"></span> Manage Expenses</a>
</div>
<div class="sidebar-heading">Settings </div>
<div class="list-group list-group-flush">
<a href="profile.php" class="list-group-item list-group-item-action "><span data-feather="user"></span> Profile</a>
<a href="logout.php" class="list-group-item list-group-item-action "><span data-feather="power"></span> Logout</a>
</div>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<nav class="navbar navbar-expand-lg navbar-light border-bottom">
<button class="toggler" type="button" id="menu-toggle" aria-expanded="false">
<span data-feather="menu"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="index.php">Dashboard</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img class="img img-fluid rounded-circle" src="<?php echo $userprofile ?>" width="25">
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="profile.phcol-mdp">Your Profile</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="logout.php">Logout</a>
</div>
</li>
</ul>
</div>
</nav>
<div class="container-fluid">
<h3 class="mt-4">Add or Edit Expenses</h3>
<p>Manage anywhere anytime</p>
<div class="row">
<div class="col-md" style="margin:0 auto;">
<form action="" method="POST">
<div class="form-group row">
<label for="expenseamount" class="col-sm-2 col-form-label">Enter Amount (₹)</label>
<div class="col-md-6">
<input type="number" class="form-control col-sm-4" value="<?php echo $expenseamount; ?>" id="expenseamount" name="expenseamount" required>
</div>
</div>
<div class="form-group row">
<label for="expensedate" class="col-sm-2 col-form-label">Date</label>
<div class="col-md-6">
<input type="date" class="form-control col-sm-4" value="<?php echo $expensedate; ?>" name="expensedate" id="expensedate" required>
</div>
</div>
<fieldset class="form-group">
<div class="row">
<legend class="col-form-label col-sm-2 pt-0">Category</legend>
<div class="col-md">
<div class="form-check">
<input class="form-check-input" type="radio" name="expensecategory" id="expensecategory1" value="Entertainment" <?php echo ($expensecategory == 'Entertainment') ? 'checked' : '' ?>>
<label class="form-check-label" for="expensecategory1">
Entertainment
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="expensecategory" id="expensecategory2" value="Bills & Recharges" <?php echo ($expensecategory == 'Bills & Recharges') ? 'checked' : '' ?>>
<label class="form-check-label" for="expensecategory2">
Bills & Recharges
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="expensecategory" id="expensecategory3" value="Food" <?php echo ($expensecategory == 'Food') ? 'checked' : '' ?>>
<label class="form-check-label" for="expensecategory3">
Food
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="expensecategory" id="expensecategory4" value="Medicine" <?php echo ($expensecategory == 'Medicine') ? 'checked' : '' ?>>
<label class="form-check-label" for="expensecategory4">
Medicine
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="expensecategory" id="expensecategory5" value="Others" <?php echo ($expensecategory == 'Others') ? 'checked' : '' ?>>
<label class="form-check-label" for="expensecategory5">
Others
</label>
</div>
</div>
</div>
</fieldset>
<div class="form-group row">
<div class="col-md-6 text-right">
<?php if ($update == true) : ?>
<button class="btn btn-lg btn-block btn-warning" type="submit" name="update">Update</button>
<?php elseif ($del == true) : ?>
<button class="btn btn-lg btn-block btn-danger" type="submit" name="delete">Delete</button>
<?php else : ?>
<button type="submit" name="add" class="btn btn-lg btn-block btn-primary">Add Expense</button>
<?php endif ?>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
<!-- Bootstrap core JavaScript -->
<script src="js/jquery.slim.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/Chart.min.js"></script>
<!-- Menu Toggle Script -->
<script>
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
</script>
<script>
feather.replace();
</script>
<script>
</script>
</body>
</html>