This repository has been archived by the owner on Jun 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buy.php
148 lines (131 loc) · 3.82 KB
/
buy.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
<?php
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Choose items & Quantity</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<br><br><br><br>
<div class="container" id="login" >
<h2>Enter Your Details:</h2>
<form action="" method="post">
<div class="form-group ">
<label for="name">Username:</label>
<input type="text" class="form-control" id="name" placeholder="Enter username" name="uname" value=<?php echo "" ?>>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pswd" value=<?php echo "" ?>>
</div>
<br>
<input type="submit" name="submit" class="btn btn-primary btn-block" style="background: #222;" value="Order"></input>
<br>
</form>
</div>
<br>
<div class="container">
<h2>Buy the things you want!</h2>
<br>
<form method="post" action="">
<div class="form-group">
<label for="sell">Select category</label>
<select class="form-control" name="type" id="sell" >
<option>Meat</option>
<option>Egg</option>
<option>Sliced</option>
<option>Chicken</option>
</select>
<br>
</div>
<div class="form-group">
<label for="qty">Quantity:</label>
<input type="number" name="qty" class="form-control" id="qty">
</div>
<div class="form-group">
<label for="add">Address:</label>
<input type="text" name="add" class="form-control" id="add">
</div>
<br>
<input class="btn btn-block btn-success" type="button" name="order" value="Order" onclick="show()">
</form>
</div>
<style>
#login{
display: none;
position: relative;
background: #888;
padding:10px 30px;
color: #222;
font-size: 20px;
border-radius: 5px;
}
#login h2{
font-size: 30px;
font-weight: 900;
color: #fff;
}
#login input{
background: rgba(255,255,255,0.8);
}
</style>
<script>
function show(){
document.getElementById('login').style.display='block';
}
</script>
</body>
<?php
$link = new mysqli("localhost","root",'',"poultry_db");
$uname="";
$pass="";
$pr=mysqli_query($link,"SELECT * from price");
while($row=mysqli_fetch_array($pr)){
$chik=$row['chicken'];
$mt=$row['meal'];
$sl=$row['sliced'];
$eg=$row['egg'];
}
if(isset($_POST['order'])){
$amt=0;
$qty=$_POST['qty'];
if($_POST['type']==='chicken'){
$amt=$chik * $qty;
}
if($_POST['type']==='sliced'){
$amt=$sl * $qty;
}
if($_POST['type']==='meat'){
$amt=$mt * $qty;
}
if($_POST['type']==='egg'){
$amt=$eg * $qty;
}
}
if(isset($_POST['submit'])){
$query= mysqli_query($link, "SELECT * from `customer` where `username`='$_POST[uname]' ");
while($row=mysqli_fetch_array($query)){
$uname=$row['username'];
$pass=$row['password'];
$cid=$row['id'];
}
if($uname===$_POST['uname'] && $pass===$_POST['pswd']){
$ins=mysqli_query($link, "INSERT INTO `order`(`order_id`, `cid`, `quantity`, `address`, `order_name`,`amount`)
VALUES (NULL,'$cid','$_POST[qty]','$_POST[add]','$_POST[type]','$amt')");
?>
<script>
window.location.href="order.php";
</script>
<?php
}
else{
echo "<center>Wrong Password or Username!</cenetr>";
}
}
?>
</html>