-
Notifications
You must be signed in to change notification settings - Fork 3
/
itemlist.php
195 lines (179 loc) · 6.42 KB
/
itemlist.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
<?php
if(isset($_POST['itemname']) && isset($_POST['itemprice']) && isset($_POST['itemlabour'])){
include "db.php";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO `item_list` (`srno`, `item_name`, `item_price`, `item_labour`) VALUES (NULL, '".$_POST['itemname']."', '".$_POST['itemprice']."', '".$_POST['itemlabour']."');";
if(isset($_POST['itemno'])){
$sql = "DELETE FROM item_list WHERE srno=".$_POST['itemno'];
$conn->query($sql);
$sql = "INSERT INTO `item_list` (`srno`, `item_name`, `item_price`, `item_labour`) VALUES (".$_POST['itemno'].", '".$_POST['itemname']."', '".$_POST['itemprice']."', '".$_POST['itemlabour']."');";
}
if ($conn->query($sql) === TRUE) {
//echo "New record created successfully";
} else {
//echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>SmartBills - Item List</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/jquery.dataTables.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<link href='css/opensans.css' rel='stylesheet' type='text/css'>
<style>
body{
font-family: 'Open Sans';
}
</style>
<script>
$(document).ready(function() {
$('#example').DataTable({
"pageLength": 50
});
} );
</script>
</head>
<body>
<?php include "navbar.php"; ?>
<div class="container">
<h1>Item List<div class="pull-right">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">Add New</button>
</div></h1>
<table class="table table-bordered" id="example">
<thead>
<tr>
<th>Item Name</th>
<th>Price</th>
<th>Labour</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
include "db.php";
$sql = "SELECT * FROM `bill`";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM item_list";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<tr>
<td><?=$row['item_name']?></td>
<td><?=$row['item_price']?></td>
<td><?=$row['item_labour']?></td>
<td align="center"><button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal<?=$row['srno']?>">
<i class="fa fa-cog" aria-hidden="true"></button></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
<?php
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<!-- Modal -->
<div id="myModal<?=$row['srno']?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Address</h4>
</div>
<div class="modal-body">
<form method="post">
<div class="form-group hidden">
<label for="itemname">Item No:</label>
<input type="text" class="form-control" id="itemno" name="itemno" required value="<?=$row['srno']?>">
</div>
<div class="form-group">
<label for="itemname">Item Name:</label>
<input type="text" class="form-control" id="itemname" name="itemname" value="<?=$row['item_name']?>" required>
</div>
<div class="form-group">
<label for="itemprice">Item Price:</label>
<input type="number" class="form-control" id="itemprice" step="any" value="<?=$row['item_price']?>" name="itemprice" required>
</div>
<div class="form-group">
<label for="itemlabour">Labour:</label>
<input type="number" class="form-control" id="itemlabour" step="any" value="<?=$row['item_labour']?>" name="itemlabour" required>
</div>
<div class="form-group">
<button class="btn btn-info">Submit</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
}
}
$conn->close(); ?>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add new Address</h4>
</div>
<div class="modal-body">
<form method="post">
<div class="form-group">
<label for="itemname">Item Name:</label>
<input type="text" class="form-control" id="itemname" name="itemname" required>
</div>
<div class="form-group">
<label for="itemprice">Item Price:</label>
<input type="number" class="form-control" id="itemprice" step="any" name="itemprice" required>
</div>
<div class="form-group">
<label for="itemlabour">Labour:</label>
<input type="number" class="form-control" id="itemlabour" step="any" name="itemlabour" required>
</div>
<div class="form-group">
<button class="btn btn-info">Submit</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>