-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyproducts.php
93 lines (75 loc) · 4.41 KB
/
myproducts.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
<?php
session_start();
$message=[];
include('dbconnection.php');
$user_id = $_SESSION['user_id'];
if(isset($_POST['submit']) && $_POST['submit']==='delete'){
$prod_id = $conn->real_escape_string($_POST['prod_id']);
$sql ="DELETE FROM products WHERE id=$prod_id";
if ($conn->query($sql) === TRUE) {
$_SESSION['flash_message']= array("category"=>"success","message"=>"Product deleted successfully");
} else {
echo "Unable to delete product " . $sql . "<br>" . $conn->error;
$message=array("category"=>"danger","message"=>"Unable to delete product " . $sql . "<br>" . $conn->error);
}
}
$sql = "SELECT * FROM products WHERE user_id='$user_id'";
$products= $conn->query($sql);
?>
<!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">
<link rel="stylesheet" href="static/bootstrap-5.1.1-dist/css/bootstrap.min.css">
<script src="static/bootstrap-5.1.1-dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="static/css/style.css">
<title>Trevos::My Products</title>
</head>
<body>
<main role="main" class="container">
<?php include'includes/navbar.php'; ?>
<section class="text-center mt-5 mb-5">
<hr class=" col-8 offset-2 mb-5">
<div class="ms-lg-5">
<div class="row">
<?php
if($products->num_rows>0){
while($product = $products->fetch_assoc()){
?>
<div class="col-lg-2 col-md-6 mx-5 mb-5">
<div class="card">
<img src=<?php echo('"media/uploads/'.$product['picture']).'"'?> alt="" >
<div class="card-body text-center">
<h5><strong><?php echo $product['productname'] ?></strong></h5>
<h6 class="font-weight-bold blue-text"><strong><?php echo('$'.$product['price']) ?></strong></h6>
</div>
<div class="row mb-3 px-3">
<form action="editProduct.php" method="POST" class="col">
<input type="hidden" name="prod_id" value=<?php echo $product['id']?>>
<input type="hidden" name="prod_name" value="<?php echo $product['productname']?>">
<input type="hidden" name="prod_desc" value="<?php echo $product['description']?>">
<input type="hidden" name="prod_price" value="<?php echo $product['price']?>">
<input type="hidden" name="prod_pic" value="<?php echo $product['picture']?>">
<button type="submit" name='submit' value="edit" class="btn btn-outline-primary btn-sm">Edit</button>
</form>
<form action="" method="POST" class="col">
<input type="hidden" name="prod_id" value=<?php echo $product['id']?>>
<button type="submit" name='submit' value="delete" class="btn btn-outline-warning btn-sm ">Delete</button>
</form>
</div>
</div>
</div>
<?php }
}else{
echo" You have not added any products yet";
}
?>
</div>
</div>
</section>
</main>
<?php include'includes/footer.php'; ?>
</body>
</html>