-
Notifications
You must be signed in to change notification settings - Fork 0
/
Productpurchasebill.php
241 lines (213 loc) · 7.55 KB
/
Productpurchasebill.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
<?php
include("header.php");
include("dbconnection.php");
if($_SESSION['randnumber'] == $_POST['randnumber'])
{
if(isset($_POST['submit']))
{
if(isset($_GET['editid']))
{
$sql ="UPDATE product_purchase_bill SET `country_id`='$_POST[country]', `state_id`='$_POST[state]', `city_id`='$_POST[city]', `customer_name`='$_POST[customername]', `customer_address`='$_POST[customeraddress]', `pincode`='$_POST[pincode]', `customer_contact_number`='$_POST[contactnumber]', `purchase_date`='', `status`='$_POST[status]' WHERE product_purchase_bill_id='$_GET[editid]'";
if(!mysqli_query($con,$sql))
{
echo "Error in mysqli query";
}
else
{
echo "<script>alert('Product Purchase Bill record updated successfully...');</script>";
}
}
else
{
$sql="INSERT INTO `product_purchase_bill`(`product_purchase_bill_id`, `country_id`, `state_id`, `city_id`, `customer_name`, `customer_address`, `pincode`, `customer_contact_number`, `purchase_date`, `status`) VALUES ('','$_POST[country]','$_POST[state]','$_POST[city]','$_POST[customername]','$_POST[customeraddress]','$_POST[pincode]','$_POST[contactnumber]','','$_POST[status]')";
if(!mysqli_query($con,$sql))
{
echo "Error in mysqli query";
}
else
{
echo "<script>alert('Product Purchase Bill record inserted successfully...');</script>";
}
}
}
}
$randnumber = rand();
$_SESSION['randnumber'] = $randnumber;
if(isset($_GET['editid']))
{
$sql = "SELECT * FROM product_purchase_bill WHERE product_purchase_bill_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>Product Purchase Bill</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 Product Detail...</h4></center><hr>
<form method="post" action="" name="frmprodpurchasebill" onSubmit="return validateprodpurchasebill()">
<input type="hidden" name="randnumber" value="<?php echo $randnumber; ?>" >
<div class="form-row">
<div class="col-md-12 form-group">
Customer Name <font color="#FF0000">*</font>
<input type="text" name="customername" id="customername" value="<?php echo $rsedit['customer_name']; ?>" autofocus class="form-control">
</div>
<div class="col-md-12 form-group">
Customer Address <font color="#FF0000">*</font>
<textarea name="customeraddress" id="customeraddress" class="form-control"><?php echo $rsedit[customer_address]; ?></textarea>
</div>
<div class="col-md-4 form-group">
Country <font color="#FF0000">*</font>
<select name="country" id="country" onChange="loadstate(this.value)" class="form-control">
<option value="">Select Country</option>
<?php
$sql1 = "SELECT * FROM country where status='Active'";
$qsql1 =mysqli_query($con,$sql1);
while($rssql1 = mysqli_fetch_array($qsql1))
{
if($rssql1[country_id] == $rsedit[country_id] )
{
echo "<option value='$rssql1[country_id]' selected>$rssql1[country]</option>";
}
else
{
echo "<option value='$rssql1[country_id]'>$rssql1[country]</option>";
}
}
?>
</select>
</div>
<div class="col-md-4 form-group">
State <font color="#FF0000">*</font>
<span id='loadstate'><select name="state" id="state" class="form-control">
<option value="">Select</option>
<?php
$sql3 = "SELECT * FROM state where status='Active'";
$qsql3 =mysqli_query($con,$sql3);
while($rssql3= mysqli_fetch_array($qsql3))
{
if($rssql3['state_id'] == $rsedit['state_id'])
{
echo "<option value='$rssql3[state_id]' selected>$rssql3[state]</option>";
}
else
{
echo "<option value='$rssql3[state_id]'>$rssql3[state]</option>";
}
}
?>
</select></span>
</div>
<div class="col-md-4 form-group">
City <font color="#FF0000">*</font>
<span id='loadcity'><select name="city" id="city" class="form-control">
<option value="">Select</option>
<?php
$sql2 = "SELECT * FROM city where status='Active'";
$qsql2 =mysqli_query($con,$sql2);
while($rssql2 = mysqli_fetch_array($qsql2))
{
if($rssql2['city_id'] == $rsedit['city_id'] )
{
echo "<option value='$rssql2[city_id]' selected>$rssql2[city]</option>";
}
else
{
echo "<option value='$rssql2[city_id]'>$rssql2[city]</option>";
}
}
?>
</select></span>
</div>
<div class="col-md-6 form-group">
Pin code <font color="#FF0000">*</font>
<input type="number" name="pincode" id="pincode" value="<?php echo $rsedit['pincode']; ?>" class="form-control">
</div>
<div class="col-md-6 form-group">
Contact Number <font color="#FF0000">*</font>
<input type="number" name="contactnumber" id="contactnumber" value="<?php echo $rsedit[customer_contact_number]; ?>" class="form-control">
</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 validateprodpurchasebill()
{
var alphaspaceExp = /^[a-zA-Z\s]+$/; //Variable to validate only alphabets and space
var numericExpression = /^[0-9]+$/; //Variable to validate only numbers
if(document.frmprodpurchasebill.customername.value == "")
{
alert("Customer name should not be empty..");
document.frmprodpurchasebill.customername.focus();
return false;
}
else if(!document.frmprodpurchasebill.customername.value.match(alphaspaceExp))
{
alert("Please enter only letters Customer name..");
document.frmprodpurchasebill.customername.focus();
return false;
}
else if(document.frmprodpurchasebill.customeraddress.value == "")
{
alert("Customer address should not be empty..");
document.frmprodpurchasebill.customeraddress.focus();
return false;
}
else if(document.frmprodpurchasebill.country.value == "")
{
alert("Kindly select the country..");
document.frmprodpurchasebill.country.focus();
return false;
}
else if(document.frmprodpurchasebill.state.value == "")
{
alert("Kindly select the state..");
document.frmprodpurchasebill.state.focus();
return false;
}
else if(document.frmprodpurchasebill.city.value == "")
{
alert("Kindly select the city..");
document.frmprodpurchasebill.city.focus();
return false;
}
else if(document.frmprodpurchasebill.pincode.value == "")
{
alert("Kindly enter PIN Code..");
document.frmprodpurchasebill.pincode.focus();
return false;
}
else if(document.frmprodpurchasebill.contactnumber.value == "")
{
alert("Kindly enter Contact number..");
document.frmprodpurchasebill.contactnumber.focus();
return false;
}
else
{
return true;
}
}
</script>