-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedit-expense.php
More file actions
176 lines (152 loc) · 5.54 KB
/
edit-expense.php
File metadata and controls
176 lines (152 loc) · 5.54 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
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
<?php
session_start();
error_reporting(0);
include('.\includes\dbh.inc.php');
if (!isset($_SESSION['userId'])) {
header('location: ../login/includes/logout.inc.php');
} else {
if (isset($_GET['editid'])) {
$dateexpense = $_GET['transDate'];
$info = $_GET['transInfo'];
$type = $_GET['transType'];
$costitem = $_GET['transAmount'];
$category = strval($_GET['transCategory']);
} else {
echo "<script>alert('Something went wrong. Please try again');</script>";
}
if (isset($_POST['submit'])) {
$userid = intval($_SESSION['userId']);
$transId = intval($_GET['editid']);
$dateexpense = $_POST['dateexpense'];
$info = $_POST['info'];
$costitem = $_POST['cost'];
$category = strval($_POST['category']);
$postvar = json_encode($_POST);
echo "<script>console.log($postvar);</script>";
$query = mysqli_query($conn, "UPDATE expenses
SET transDate = '$dateexpense',
idUsers = '$userid',
transInfo = '$info',
transType = 'D',
transAmount = '$costitem',
transCategory = '$category'
WHERE transId = '$transId'");
if ($query) {
echo "<script>alert('Transaction has been updated');</script>";
echo "<script>window.location.href='manage-expense.php'</script>";
} else {
echo "<script>alert('Something went wrong. Please try again');</script>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Daily Expense Tracker || Add Expense</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/datepicker3.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
<!--Custom Font-->
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php include_once('includes/header.php'); ?>
<?php include_once('includes/sidebar.php'); ?>
<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">
<div class="row">
<ol class="breadcrumb">
<li><a href="#">
<em class="fa fa-home"></em>
</a></li>
<li class="active">Expense</li>
</ol>
</div>
<!--/.row-->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Expense</div>
<div class="panel-body">
<p style="font-size:16px; color:red" align="center"> <?php if ($msg) {
echo $msg;
} ?> </p>
<div class="col-md-12">
<form role="form" method="post" action="">
<div class="form-group">
<label>Date of Expense</label>
<input class="form-control" type="date" value="<?php echo $dateexpense; ?>" name="dateexpense" required="true">
</div>
<div class="form-group">
<label>Description</label>
<input type="text" class="form-control" name="info" value="<?php echo $info; ?>">
</div>
<div class="form-group">
<label>Cost of Item</label>
<input class="form-control" type="text" value="<?php echo $costitem; ?>" required="true" name="cost">
</div>
<div class="form-group">
<label>Category</label>
<select class="form-control" name="category" required>
<option <?php if ($category == 'bills') {
echo ("selected");
} ?> value='bills'>Bills and Utilities</option>
<option <?php if ($category == 'education') {
echo ("selected");
} ?> value='education'>Education</option>
<option <?php if ($category == 'entertainment') {
echo ("selected");
} ?> value='entertainment'>Entertaiment</option>
<option <?php if ($category == 'food') {
echo ("selected");
} ?> value='food'>Food and Beverage</option>
<option <?php if ($category == 'health') {
echo ("selected");
} ?> value='health'>Health</option>
<option <?php if ($category == 'clothing') {
echo ("selected");
} ?> value='clothing'>Clothing</option>
<option <?php if ($category == 'footwear') {
echo ("selected");
} ?> value='footwear'>Footwear</option>
<option <?php if ($category == 'transportation') {
echo ("selected");
} ?> value='bills'>Transportation</option>
<option <?php if ($category == 'personalcare') {
echo ("selected");
} ?> value='bills'>Personal Care</option>
<option <?php if ($category == 'investment') {
echo ("selected");
} ?> value='bills'>Investment</option>
</select>
</div>
<div class="form-group has-success">
<button type="submit" class="btn btn-primary" name="submit">Update</button>
</div>
</div>
</form>
</div>
</div>
</div><!-- /.panel-->
</div><!-- /.col-->
<?php include_once('includes/footer.php'); ?>
</div><!-- /.row -->
</div>
<!--/.main-->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/chart.min.js"></script>
<script src="js/chart-data.js"></script>
<script src="js/easypiechart.js"></script>
<script src="js/easypiechart-data.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/custom.js"></script>
</body>
</html>