-
Notifications
You must be signed in to change notification settings - Fork 0
/
grocerybuynow.php
102 lines (102 loc) · 2.83 KB
/
grocerybuynow.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
<?php
session_start();
if(isset($_SESSION['id']))
{
$id=$_SESSION['id'];
$model=$_GET['model'];
$con=new MySQLi("localhost","root","","project");
$sql="select * from registration,grocery where modelname='$model' and cid='$id'";
$res=$con->query($sql);
$row=$res->fetch_array();
}
else
{
echo "<script> alert('LOG IN OR SIGN UP') </script>";
echo "<script>window.location.href='index.php'</script>";
}
?>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
table, th, td {
padding: 10px;
}
table {
border-spacing: 25px;
}
</style>
<script>
function valid()
{
var pin=frm.n3.value
if(pin=="")
{
alert('enter your pincode')
return false
}
else if(pin.length!=6)
{
alert('pincode should be 6 digit')
return false
}
else if(isNaN(pin))
{
alert('enter number only')
return false
}
}
</script>
</head>
<body>
<header style="background-color:#555;height:70px">
<div style="padding-top:10px;font-color:#000000">
<a href="index.php"><i class="glyphicon glyphicon-home" style="font-size:30px;color:#ffffff;padding-left:30px">HOME</i></a>
</div>
</header><br>
<center>
<table>
<form method='post' name='frm' onSubmit="return valid()">
<tr><td>Email : </td><td><input type='text' name='n1' value="<?php echo $row[6] ?>" readonly></td></tr>
<tr><td>Enter Delivery Address : </td><td><textarea placeholder="Enter delivery address" name='n2' required></textarea></td></tr>
<tr><td>Pincode : </td><td><input type='text' placeholder="Enter pincode" name='n3' required></td></tr>
<tr><td>Model Name : </td><td><input type='text' name='n4' value="<?php echo $row[12] ?>" readonly></td></tr>
<tr><td>Price : </td><td><input type='text' name='n6' value="<?php echo $row[15] ?>" readonly></td></tr>
<tr><td>Quantity : </td><td><select name='n5'>
<?php
for($i=1;$i<=$row[17];$i++)
{
echo "<option>" .$i. "</option>";
}
?>
</select></td></tr>
<tr><td><input type="submit" style="height:38px;width:100px" value='BUY' name='btn'></td></tr>
</form>
</table>
</center>
</body>
</html>
<?php
if(isset($_POST['btn']))
{
$cid=$_SESSION['id'];
$email=$_POST['n1'];
$address=$_POST['n2'];
$pin=$_POST['n3'];
$modelname=$_POST['n4'];
$price=$_POST['n6'];
$qty=$_POST['n5'];
$total=$row[15]*$qty;
$qty1=$row[17]-$qty;
$sql1="update grocery set qty=$qty1 where modelname='$model'";
$con->query($sql1);
$ono=rand(1,99999);
$sql2="insert into orders values(null,$ono,$cid,'$email','$address','$pin','$modelname','null',$price,$qty,$total,'null')";
$con->query($sql2);
echo "<script>window.location.href='ordersummary.php?model=$row[12]'</script>";
}
?>