-
Notifications
You must be signed in to change notification settings - Fork 0
/
buyer.php
206 lines (186 loc) · 6.19 KB
/
buyer.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Buyer Hub</title>
<link rel="icon" type="image/png" href="../naistam/imgs/output-onlinegiftools.gif">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<style>
*,
*:before,
*:after{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
background-color: whitesmoke;
background-image: url(../naistam/imgs/img4.jpg);
background-repeat: no-repeat;
background-size: cover;
}
.pos2 {
text-align: center;
font-size: 60px;
}
.pos1 {
width: 500px;
height: 50px;
display:flexbox;
align-items: center;
}
.container {
text-align: center;
width: 1300px;
}
.pss{
width: 800px;
text-align: right;
}
.mg {
position: fixed;
left: 720px;
bottom: 2px;
}
.mgm {
position: fixed;
left: 528px;
bottom: 2px;
}
.money {
text-align: center;
color: black;
}
.mg:hover{
background-color: green;
}
.mgm:hover{
background-color: green;
}
</style>
<?php
$host = "localhost";
$username = "root";
$password = "";
$dbname = "sbav";
// creating a connection
$con = mysqli_connect($host, $username, $password, $dbname);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$sql = "SELECT * FROM stock WHERE 1";
$result = $con->query($sql);
$Tcost=0;
$lim=0;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['itemtype']))
{
$itemtype = $_POST['itemtype'];
$sql = "SELECT qty from stock where item='$itemtype'";
$rs1 = mysqli_query($con,$sql);
while($rows=$rs1->fetch_assoc())
{ $qty= $rows['qty'];}
$value=$_POST['updatevalue'];
if($value<=$qty)
{
$new=$qty-$value;
$sql = "UPDATE stock SET qty=$new WHERE item='$itemtype'";
$rs = mysqli_query($con,$sql);
$sql2 = "SELECT cost FROM stock WHERE item='$itemtype'";
$result2 = mysqli_query($con,$sql2);
while($rows=$result2->fetch_assoc())
{
$Tcost=intval($rows['cost'])*$value;
}
}
if($value==0)
{
echo '<script>alert("Enter more than 1 Qty");</script>';
}
if($value > $qty)
{
echo '<script>alert("Stock limit execeeded");</script>';
$lim=1;
}
if($value < $qty && $value!=0)
{
echo '<script>alert("Stock Booked Successfully");</script>';
}
}
}
$sql = "SELECT * FROM stock WHERE 1";
$result = $con->query($sql);
if (isset($_POST['submitupdate']))
{
$mn=$_POST['mobilenum'];
$name=$_POST['cname'];
if($lim!=1 && $value!=0)
{
$sin="INSERT into sales (name,mobilenum,itemPurchased,qty,cost) values('$name','$mn','$itemtype','$value','$Tcost');";
$st = $con->query($sin);
}
}
$con->close();?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
</head>
<body>
<div class="pos1"><img src="../naistam/imgs/logo.png"></div>
<h1 class='pos2'>WELCOME BACK CUSTOMER</h1></div> <br><br><br>
<div class="container" id="container">
<table border="1" class="table table-hover">
<thead class="tablehead">
<tr>
<th style="background: none;font-size: 25px;">Serial Number</th>
<th style="background: none;font-size: 25px;">Item Type</th>
<th style="background: none;font-size: 25px;">Quantity in KG</th>
<th style="background: none;font-size: 25px;">Cost in KG</th>
</tr>
</thead>
<tbody class="tablebody">
<tr>
<?php
while($rows=$result->fetch_assoc())
{
?>
<tr>
<td style="background: none;font-size: 25px;"><?php echo $rows["sno"];?></td>
<td style="background: none;font-size: 25px;"><?php echo $rows["item"];?></td>
<td style="background: none;font-size: 25px;"><?php echo $rows["qty"];?></td>
<td style="background: none;font-size: 25px;"><?php echo $rows["cost"];?></td>
</tr>
<?php
}
?>
</tr>
</tbody>
</table>
</div>
<div class='pss'>
<form method="post" action="buyer.php">
<select name='itemtype'>
<option value="plastic">Plastic</option>
<option value="iron">Iron</option>
<option value="Husk">Husk</option>
</select>
<input type="number" name="updatevalue" autocomplete="off" placeholder="Enter Quantity" required>
<input type="text" name="cname" autocomplete="off" placeholder="Enter your name" required>
<input type="number" name="mobilenum" autocomplete="off" placeholder="Enter your mobile num" required>
<input type="submit" value="Book" name="submitupdate">
</form></div>
<h1 class='money'><?php
if($Tcost>0)
echo "Total cost = ".$Tcost;
?></h1>
<div class="mg">
<button style="width:160px; background: none;"><a href="logs.php" style="color:black; text-decoration:none; font-size:larger;">Logout</a></button>
</div>
<div class="mgm">
<button style="width:160px; background: none;"><a href="about.html" style="color:black; text-decoration:none; font-size:larger;">About us</a></button>
</div>
</body>
</html>