-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
158 lines (141 loc) · 3.93 KB
/
update.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
<?php
session_start();
if (strlen($_SESSION['id']==0)) {
header('location:logout.php');
}
$id=$_GET['id'];
include('db.php');
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// update product code
if(isset($_POST['update']))
{
$target = "product-images/" .basename($_FILES['image']['name']);
$name = $_POST['name'];
$price = $_POST['price'];
$desc = $_POST['description'];
$imgfile = $_FILES['image']['name'];
$shop_id= $_SESSION['id'];
$sql = "UPDATE product SET name='$name', price='$price', description='$desc', product_image='$imgfile' WHERE pro_id = $id";
if (mysqli_query($conn, $sql)) {
move_uploaded_file($_FILES['image']['tmp_name'], $target);
echo "<script>alert('product updated successfully');</script>";
echo "<script>window.location.assign('welcome.php')</script>";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link href="https://fonts.googleapis.com/css?family=Noto Sans / Serif" rel="stylesheet">
<style type="text/css">
*{
margin:0;
padding:0;
box-sizing:border-box;
}
body{
font-family:'Noto Sans / Serif',sans-serif;
background-position: center;
background-size: cover;
background-color: #E5E8E8;
height:100%;
width: 100%;
}
h2{
text-align: center;
margin:40px 0;
}
.form-container{
width:100%;
height:auto;
padding:10px 10px 30px 10px;
}
.form-box{
width:100%;
max-width: 500px;
box-shadow: 0 10px 6px -6px #808B96;
border-radius:3px;
margin:30px auto 0;
background:white;
padding:50px 40px;
}
.form-box .input-group{
margin:25px auto;
}
.form-box .input-group input{
width: 100%;
height: 30px;
outline:none;
border:1px solid #D6DBDF;
padding:3px 0 3px 10px;
}
.form-box .input-group label{
color:#454545;
margin:0 0 4px 2px;
font-size: 13px;
}
.form-box .input-group textarea{
padding: 10px;
outline: none;
border:1px solid #D6DBDF;
}
.form-box button{
padding:10px 20px;
border:none;
border-radius:2px;
font-weight: bold;
cursor:pointer;
background-color:red;
color:#fff;
}
.form-box button:hover{
opacity:0.9;
}
.form-box span{
float:right;
font-size:15px;
color: #A6ACAF;
cursor:pointer;
margin-top:10px;
}
</style>
</head>
<body>
<h2><span style="color:red;">Edit Your</span><span> Product</span></h2>
<div class="form-container">
<div class="form-box">
<form action="" method="post" enctype="multipart/form-data">
<div class="input-group">
<?php
$sql = "SELECT * FROM product WHERE pro_id = $id";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
?>
<label for="name">Product name</label>
<input type="text" placeholder="Product name" name="name" value="<?php echo $row['name']; ?>">
</div>
<div class="input-group">
<label for="price">Price</label>
<input type="text" placeholder="Price" name="price" value="<?php echo $row['price']; ?>">
</div>
<div class="input-group">
<label for="description">Product drscription</label>
<textarea id="description" placeholder="type product description" rows="7" cols="48" maxlength="1000" name="description"><?php echo $row['description']; ?></textarea>
</div>
<div class="input-group">
<label >Upload product image</label>
<input type="file" name="image" value="<?php echo $row['product_image']; ?>" required>
</div>
<button type="submit" name ="update">Update</button>
<span onclick="window.location.assign('welcome.php');">Cancel</span>
</form>
</div>
</div>
</body>
</html>