-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
132 lines (99 loc) · 3 KB
/
index.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
<?php
include'header.php';
// include'lib/connection.php';
$sql = "SELECT * FROM product";
$result = $conn -> query ($sql);
if(isset($_POST['add_to_cart'])){
if(isset($_SESSION['auth']))
{
if($_SESSION['auth']!=1)
{
header("location:login.php");
}
}
else
{
header("location:login.php");
}
$user_id=$_POST['user_id'];;
$product_name = $_POST['product_name'];
$product_price = $_POST['product_price'];
$product_id = $_POST['product_id'];
$product_quantity = 1;
$select_cart = mysqli_query($conn, "SELECT * FROM `cart` WHERE productid = '$product_id' && userid='$user_id'");
if(mysqli_num_rows($select_cart) > 0){
echo $message[] = 'product already added to cart';
}else{
$insert_product = mysqli_query($conn, "INSERT INTO `cart`(userid, productid, name, quantity, price) VALUES('$user_id', '$product_id', '$product_name', '$product_quantity', '$product_price')");
echo $message[] = 'product added to cart succesfully';
header('location:index.php');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
</div>
<div class="col-md-6">
<img src="" class="img-fluid">
</div>
</div>
</div>
</div>
<!--banner end-->
<!---top sell start---->
<section>
<div class="container">
<div class="topsell-head">
<div class="row">
<div class="col-md-12 text-center">
<h4>All Products</h4>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<?php
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="col-md-3 col-sm-6 col-6">
<div>
<img src="admin/product_img/<?php echo $row['imgname']; ?>" >
</div>
<div>
<div>
<h6><?php echo $row["name"] ?></h6>
<span><?php echo $row["Price"] ?></span>
<input type="hidden" name="user_id" value="<?php echo $_SESSION['userid'];?>" >
<input type="hidden" name="product_id" value="<?php echo $row['id']; ?>">
<input type="hidden" name="product_name" value="<?php echo $row['name']; ?>">
<input type="hidden" name="product_price" value="<?php echo $row['Price']; ?>">
</div>
<input type="submit" class="btn btn btn-primary" value="add to cart" name="add_to_cart">
</div>
</div>
</form>
<?php
}
}
else
echo "0 results";
?>
</div>
</div>
</section>
<?php
include'footer.php';
?>