-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode1.php
More file actions
80 lines (69 loc) · 2.97 KB
/
Copy pathcode1.php
File metadata and controls
80 lines (69 loc) · 2.97 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>add product</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<?php
include '../db.php';
session_start();
if (isset($_POST["edit_id"])) {
$_SESSION['cartid'] = $_POST["edit_id"];
}
$productId = $_SESSION['productid'];
// Editing product
if (isset($_POST["submit"])) {
$p_name = $_POST['item_name'];
$p_price = $_POST['total_item'];
$query = "UPDATE `cart` SET `item_name`='$item_name',`total_item`='$total_item'";
$result = mysqli_query($con, $query);
if ($result) {
echo '<script>alert("Product added successfully")</script>';
} else {
echo "<div class='form'>
<h3>Required fields are missing.</h3><br/>
<p class='link'>Click here to <a href='add.php'>add product</a> again.</p>
</div>";
}
}
// When form submitted, insert values into the database.
if (isset($_POST["edit_id"])) {
$queryingProduct = "SELECT * FROM `cart` WHERE `id`=$cart_id";
$products = $con->query($queryingProduct);
if ($products->num_rows > 0) {
while ($eachProduct = $products->fetch_assoc()) {
?>
<form class="form" action="" method="post" enctype="multipart/form-data">
<h1 class="login-title">Edit CART</h1>
<input type="text" class="login-input" name="p_name" value="<?php echo $eachProduct['p_name']; ?>" placeholder="product name" required />
<input type="text" class="login-input" name="p_price" value="<?php echo $eachProduct['p_price']; ?>" placeholder="price" required />
<select name='category'>
<?php
$result1 = "SELECT * from category";
$result = $con->query($result1);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if ($row['category_id'] == $eachProduct['category_id']) {
echo '<option selected value="' . $row['category_id'] . '">' . $row['category_name'] . '</option>';
} else {
echo '<option value="' . $row['category_id'] . '">' . $row['category_name'] . '</option>';
}
}
}
?>
</select>
<input type="text" class="login-input" name="p_description" value="<?php echo $eachProduct['p_description']; ?>" placeholder="description" required />
<input type="submit" name="submit" value="Edit" class="login-button">
</form>
<?php
}
}
} else {
header("Location: ./p_edit.php");
die();
}
?>
</body>
</html>