-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.php
293 lines (270 loc) · 8.28 KB
/
state.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
include("header.php");
//Insert statement starts here
if(isset($_POST['submit']))
{
if(isset($_GET['editid']))
{
$sql="UPDATE state SET state='$_POST[state]', statecode='$_POST[statecode]',
discription='$_POST[discription]',status='$_POST[status]' WHERE stateid='$_GET[editid]'";
$qsql = mysqli_query($con,$sql);
if(mysqli_affected_rows($con) == 1)
{
echo "<script>alert('state updated successfully');</script>";
echo "<script>window.location='state.php';</script>";
}
else
{
echo mysqli_error($con);
}
}
else
{
$sql="INSERT INTO state (state, statecode, discription,status)VALUES
('$_POST[state]','$_POST[statecode]','$_POST[discription]',
'$_POST[status]')";
$qsql = mysqli_query($con,$sql);
if(mysqli_affected_rows($con) == 1)
{
echo "<script>alert('Registration done successfully');</script>";
echo "<script>window.location='state.php';</script>";
}
else
{
echo mysqli_error($con);
}
}
}
//Insert statement ends here
//Delete statement starts here
if(isset($_GET['delid']))
{
$sql ="DELETE FROM state WHERE stateid='$_GET[delid]'";
$qsql = mysqli_query($con,$sql);
if(mysqli_affected_rows($con) == 1)
{
echo "<script>alert('State record deleted successfully');</script>";
echo "<script>window.location='state.php';</script>";
}
else
{
echo mysqli_error($con);
}
}
//Delete statement ends here
//Edit statement starts here
if(isset($_GET['editid']))
{
$sqledit ="SELECT * FROM state WHERE stateid='$_GET[editid]'";
$qsqledit = mysqli_query($con,$sqledit);
$rsedit = mysqli_fetch_array($qsqledit);
}
//Edit statement ends here
?>
<!--banner -->
<!-- Slideshow 4 -->
<div class="slider">
<div class="callbacks_container">
<ul class="rslides" id="slider4">
<li style="background-color:black;height:150px;">
</li>
</ul>
</div>
<!-- This is here just to demonstrate the callbacks -->
<!-- <ul class="events">
<li>Example 4 callback events</li>
</ul>-->
<div class="clearfix"></div>
</div>
</div>
<!-- //banner -->
<!--about-->
<section class="about" id="about">
<div class="container py-lg-5 py-md-5 py-sm-4 py-3">
<!--Horizontal Tab-->
<div id="horizontalTab">
<ul class="resp-tabs-list justify-content-center">
<li data-blast="bgColor">State</li>
<li data-blast="bgColor">View State</li>
</ul>
<div class="resp-tabs-container">
<div class="tab1">
<div class="row mt-lg-4 mt-3">
<div class="col-md-5 about-txt-img">
<img src="images/register.jpg" class="img-thumbnail" width="100%">
</div>
<div class="col-md-7 latest-list">
<div class="about-jewel-agile-left">
<h5 class="mb-3" data-blast="color">State Registration </h5>
<p>
<form action="" method="post" onsubmit="return validateform()">
<div class="form-group">
<label for="email">State:<span class="classvalidate" id="idstate"></span></label>
<input type="text" class="form-control" id="state" placeholder="Enter State" name="state" value="<?php echo $rsedit['state']; ?>">
</div>
<div class="form-group">
<label for="email">StateCode :<span class="classvalidate" id="idstatecode"></span></label>
<input type="text" class="form-control" id="statecode" placeholder="Enter StateCode" name="statecode" value="<?php echo $rsedit['statecode']; ?>">
</div>
<div class="form-group">
<label for="email">Description:<span class="classvalidate" id="iddiscription"></span></label>
<textarea class="form-control" id="discription" placeholder="Enter Discription" name="discription"><?php echo $rsedit['discription']; ?></textarea>
</div>
<div class="form-group">
<label for="email">Status:<span class="classvalidate" id="idstatus"></span></label>
<select id="status" name="status" class="form-control">
<option value="">Select status</option>
<?php
$arr = array("Active","Inactive");
foreach($arr as $val)
{
if($val == $rsedit['status'])
{
echo "<option value='$val' selected>$val</option>";
}
else
{
echo "<option value='$val'>$val</option>";
}
}
?>
</select>
</div>
<button type="submit" name="submit" class="btn btn-info">Click here to Submit</button>
</form>
</p>
</div>
</div>
</div>
</div>
<div class="tab2">
<div class="row mt-lg-4 mt-3">
<div class="col-md-12 about-txt-img">
<table border="1" id="myTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>State</th>
<th>Statecode</th>
<th>Discription</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM state";
$qsql= mysqli_query($con,$sql);
while($rs = mysqli_fetch_array($qsql))
{
echo "<tr>
<td>$rs[state]</td>
<td>$rs[statecode]</td>
<td>$rs[discription]</td>
<td>$rs[status]</td>
<td><a href='state.php?editid=$rs[0]' class='btn btn-info'>Edit</a>
<a href='state.php?delid=$rs[0]' class='btn btn-danger' onclick='return confirmdel()'>Delete</a></td>
</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!--//about-->
<!--footer-->
<div class="nav-footer py-sm-4 py-3">
<div class="container-fluid">
<div class="buttom-nav ">
<nav class="border-line py-2">
<ul class="nav justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a href="#about" class="nav-link scroll">About</a>
</li>
<li class="nav-item">
<a href="#service" class="nav-link scroll">Services</a>
</li>
<li class="nav-item">
<a href="#blog" class="nav-link scroll">Blog</a>
</li>
<li class="nav-item">
<a href="#contact" class="nav-link scroll">Contact</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<?php
include("footer.php");
?>
<script>
$(document).ready( function () {
$('#myTable').DataTable();
} );
</script>
<script>
function confirmdel()
{
if(confirm("Are you sure want to delete this record?") == true)
{
return true;
}
else
{
return false;
}
}
</script>
<script>
function validateform()
{
var numericExpression = /^[0-9]+$/;
var alphaExp = /^[a-zA-Z]+$/;
var alphaspaceExp = /^[a-zA-Z\s]+$/;
var alphaNumericExp = /^[0-9a-zA-Z]+$/;
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
var validateform="true";
$( ".classvalidate" ).empty();
if(document.getElementById("state").value=="")
{
document.getElementById("idstate").innerHTML="State Should not be empty...";
validateform="false";
}
if(document.getElementById("discription").value=="")
{
document.getElementById("iddiscription").innerHTML="Discription Should not be empty...";
validateform="false";
}
if(!document.getElementById("statecode").value.match(numericExpression))
{
document.getElementById("idstatecode").innerHTML="Statecode should contain numbers...";
validateform="false";
}
if(document.getElementById("statecode").value=="")
{
document.getElementById("idstatecode").innerHTML="Statecode Should not be empty...";
validateform="false";
}
if(document.getElementById("status").value=="")
{
document.getElementById("idstatus").innerHTML="Status Should not be empty...";
validateform="false";
}
if(validateform=="true")
{
return true;
}
else
{
return false;
}
}
</script>