-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsell.php
208 lines (195 loc) · 7.51 KB
/
sell.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
<?php session_start();
if(!isset($_SESSION['userid']) or !isset($_SESSION['username'])){
header('location:index.php');
}
require_once('connect.php');
$err = $notify = "";
if(isset($_POST['Submit'])){
$pname = $_POST['pname'];
$details = $_POST['paragraph_text'];
$img_name = $_FILES['pimg']['name'];
$price = (string)$_POST['price'];
$bkey = $_POST['pkey'];
$findby= "";
include_once('validation.php');
if(validate_email($_SESSION['userid'])=='good')
$findby = "email";
else if(validate_roll($_SESSION['userid'])=='good')
$findby = "roll";
$stmt1=$con->prepare('SELECT roll FROM `users` WHERE '.$findby.'=?');
$stmt1->bind_param('s',$_SESSION['userid']);
$stmt1->execute();
$res1 = $stmt1->get_result();
$stmt1->close();
$row1 = $res1->fetch_assoc();
$ownername = $row1['roll'];
$stmt = $con->prepare("INSERT INTO `products`(`name` ,`img` ,`details` ,`ownerroll` , `price`, `buyingkey` ) VALUES(?,?,?,?,?,?)");
$stmt->bind_param("ssssss", $pname, $img_name, $details, $ownername, $price, $bkey);
if($stmt->execute()){
$move = move_uploaded_file($_FILES['pimg']['tmp_name'], 'up/'.$img_name);
if($move){
$notify = "Added your product for Sell<br>Bring more there are lots of buyer...";
$err = "";
}
}
else{
$notify = "";
$err = "INSERTION FAILED";
}
$stmt->close();
}
if(isset($_POST['delete'])){
// echo $_POST['delete'];
$pid = explode("+",$_POST['delete']);
$stmt3 = "";
if($pid[1]=='available')
$stmt3 = $con->prepare("UPDATE `products` SET `status` = 'cancelled' WHERE p_id = ?");
else
$stmt3 = $con->prepare("UPDATE `products` SET `status` = 'available' WHERE p_id = ?");
$stmt3->bind_param('i', $pid[0]);
$stmt3->execute();
$res3 = $stmt3->get_result();
$stmt3->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>buy&sell</title>
<!-- Meta Tags -->
<meta charset="utf-8">
<meta html-equiv = "X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" type="text/css" href="css/sell.css" media="screen">
<!-- FONTS -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Allerta+Stencil">
<!-- Symbol -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- STYLE -->
<style type="text/css">
@import url('https://fonts.googleapis.com/css2?family=Philosopher&display=swap');
</style>
</head>
<body>
<!-- HEADER -->
<header>
<div class="text-center"> <a href="./buy.php">BUY</a> and <a href="./sell.php">SELL</a>
<div class="sym user text-secondary"><div class="hide"> <?php echo $_SESSION['username']; ?></div>
<a href="logout.php">
<i class="fa text-secondary">

</i>
</a>
</div>
</div>
</header>
<!-- MAIN CONTAINT -->
</br></br></br></br>
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<?php
$findby= "";
include_once('validation.php');
if(validate_email($_SESSION['userid'])=='good')
$findby = "email";
else if(validate_roll($_SESSION['userid'])=='good')
$findby = "roll";
$stmt1=$con->prepare('SELECT roll FROM `users` WHERE '.$findby.'=?');
$stmt1->bind_param('s',$_SESSION['userid']);
$stmt1->execute();
$res1 = $stmt1->get_result();
$stmt1->close();
if($row1 = $res1->fetch_assoc()){
$stmt2 = $con->prepare("SELECT * FROM `products` WHERE ownerroll = ? ");
$stmt2->bind_param('s', $row1['roll']);
$stmt2->execute();
$res2 = $stmt2->get_result();
$stmt2->close();
$found = false;
while($row2 = $res2->fetch_assoc()){
$found = true;
if($row2['status']){
?>
<div class="wrapper">
<div class="product-img">
<?php
$imgname = $row2['img'];
if(strlen($row2['img'])>0){
echo "<img class='card-img-top' src='up/$imgname' width='420' height='327' alt='NO IMAGE'>";
}else{
echo '<img class="card-img-top" src="up/default.png" width="420" height="327">';
}
?>
</div>
<div class="product-info">
<div class="product-text">
<h1><?php echo $row2['name'];?></h1>
<p><?php echo $row2['details']; ?></p>
</div>
<div class="product-price-btn" style="display: inline-flex;">
<form method="POST" action="#">
<?php if($row2['status'] == "cancelled"){ ?>
<button class="dlt-dis" name="delete" value="<?php echo $row2['p_id']."+".$row2['status']; ?>" type="submit" >Sell</button>
<?php }else{?>
<button class="dlt" name="delete" value="<?php echo $row2['p_id']."+".$row2['status']; ?>" type="submit">Cancel</button>
<?php }?>
</form>
<!-- <button name="edit" value="<?php //echo $row2['p_id']; ?>" type="submit">
₹ <?php //echo $row2['price']; ?> edit
</button> -->
</div>
</div>
</div>
<?php
}
}
if(!$found){
echo '<img src="img/shopping.svg" class="img-fluid">';
}
}
?>
</div>
<div class="col-md-6">
</br>
<br><div class="title text-center"> ADD PRODUCT </div><br>
</br>
<p style="color:red"><b><?php echo $err; ?></b></p>
<p style="color:green"><b><?php echo $notify; ?></b></p>
<form method="POST" action="sell.php" enctype="multipart/form-data">
<div class="lable">
PRODUCT NAME : <input type="text" id="productName" class="form-control" placeholder="PRODUCT NAME" name="pname" style="width: 70%;" required />
</div>
<div class="lable">
IMAGE :
<img id="blah" src="img/cam.png" width="100" height="100" />
<input type="file" name="pimg" accept=".jpg,.gif,.jpeg,.png" onchange="document.getElementById('blah').src = window.URL.createObjectURL(this.files[0])" required>
</div>
<div class="lable">
DETAILS : <br><textarea name="paragraph_text" rows="5" id="details" class="form-control" placeholder="Give details of the product (max character 100)." name="detail" required></textarea>
</div>
<div class="bind">
<div class="lable">
PRICE : <input type="number" id="price" class="form-control" placeholder="PRICE" name="price" style="width: 50%;" required />
</div>
<div class="lable">
PRODUCT KEY : <input type="text" id="key" class="form-control" placeholder="Product Key" name="pkey" style="width: 50%;" required />
</div>
</div>
</br></br>
<center>
<input class="button " type="submit" value="Submit" name="Submit">
</center>
</br></br></br>
</form>
</div>
</div>
</div>
</br></br></br>
<!-- FOOTER -->
<footer>2020 © Made with <font color="red">♥</font> by <a href="https://github.com/mayankmohak">Mayank Mohak</a> </footer>
</body>
</html>