-
Notifications
You must be signed in to change notification settings - Fork 0
/
city.php
191 lines (165 loc) · 4.7 KB
/
city.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
<?php
include("header.php");
if(!isset($_SESSION['adminid']))
{
echo "<script>window.location='adminloginpanel.php'; </script>";
}
if($_SESSION['randnumber'] == $_POST['randnumber'])
{
if(isset($_POST['submit']))
{
if(isset($_GET['editid']))
{
$sql ="UPDATE city SET `state_id`='$_POST[state]', `city`='$_POST[city]', `description`='$_POST[description]', `status`='$_POST[status]' WHERE city_id='$_GET[editid]'";
if(!mysqli_query($con,$sql))
{
echo "Error in mysqli query";
}
else
{
echo "<script>alert('City record updated successfully...');</script>";
}
}
else
{
$sql="INSERT INTO `city`(`city_id`, `state_id`, `city`, `description`, `status`) VALUES ('','$_POST[state]','$_POST[city]','$_POST[description]','$_POST[status]')";
if(!mysqli_query($con,$sql))
{
echo "Error in mysqli query" . mysqli_error($con);
}
else
{
echo "<script>alert('City record inserted successfully...');</script>";
}
}
}
}
$randnumber = rand();
$_SESSION['randnumber'] = $randnumber;
if(isset($_GET['editid']))
{
$sql = "SELECT * FROM city WHERE city_id='$_GET[editid]'";
$qsql = mysqli_query($con,$sql);
$rsedit = mysqli_fetch_array($qsql);
}
?>
<main id="main">
<!-- ======= Cta Section ======= -->
<section id="cta" class="cta">
<div class="container">
<div class="text-center" data-aos="zoom-in">
<br><br>
<h3>City</h3>
</div>
</div>
</section><!-- End Cta Section -->
<!-- ======= Contact Section ======= -->
<section id="contact" class="contact">
<div class="container">
<div class="row">
<div class="col-lg-12" data-aos="fade-up" data-aos-delay="100">
<div class="info mt-4 ">
<center><h4>Enter City record...</h4></center><hr>
<form method="post" action="" name="frmcity" onSubmit="return validatecity()">
<input type="hidden" name="randnumber" value="<?php echo $randnumber; ?>" >
<div class="form-row">
<div class="col-md-12 form-group">
State <font color="#FF0000">*</font>
<span id='loadstate'><?php include("ajaxstate.php");?></span>
</div>
<div class="col-md-12 form-group">
City <font color="#FF0000">*</font>
<input type="text" name="city" id="city" class="form-control" value="<?php echo $rsedit['city']; ?>" >
</div>
<div class="col-md-12 form-group">
Description <font color="#FF0000">*</font>
<textarea name="description" id="description" class="form-control" ><?php echo $rsedit['description']; ?></textarea>
</div>
<div class="col-md-12 form-group">
Status <font color="#FF0000">*</font>
<select name="status" id="status" class="form-control">
<option value="">Select Status</option>
<?php
$arr= array("Active","Inactive");
foreach($arr as $val)
{
if($rsedit['status'] == $val)
{
echo "<option value='$val' selected >$val</option>";
}
else
{
echo "<option value='$val'>$val</option>";
}
}
?>
</select>
</div>
</div>
<hr>
<button type="submit" name="submit" id="submit" class="btn btn-info btn-lg btn-block" >Submit</button>
</form>
</div>
</div>
</div>
</div>
</section><!-- End Contact Section -->
</main><!-- End #main -->
<?php
include("footer.php");
?>
<script type="application/javascript">
function validatecity()
{
var alphaspaceExp = /^[a-zA-Z\s]+$/; //Variable to validate only alphabets and space
if(document.frmcity.country.value == "")
{
alert("Kindly select the country..");
document.frmcity.country.focus();
return false;
}
else if(document.frmcity.state.value == "")
{
alert("Kindly select the state..");
document.frmcity.state.focus();
return false;
}
else if(document.frmcity.city.value == "")
{
alert("Enter city..");
document.frmcity.city.focus();
return false;
}
else if(!document.frmcity.value.match(alphaspaceExp))
{
alert("Please enter only letters for city name..");
document.frmcity.city.focus();
return false;
}
else
{
return true;
}
}
function loadstate(id) {
if (id == "") {
document.getElementById("loadstate").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("loadstate").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","ajaxstate.php?id="+id,true);
xmlhttp.send();
}
}
</script>