-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproduct.php
77 lines (68 loc) · 2.74 KB
/
product.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
<?php
require_once('config.php');
//session
session_start();
if($_SESSION['logged'] != 1){
header("Location: login.php");
}
$product = $_GET['item'];
$queryItem = "SELECT * FROM products WHERE id = '$product'";
$doItem = mysqli_query($conn, $queryItem) or die(mysqli_error($conn));
$fetchItem = mysqli_fetch_assoc($doItem);
$iname = $fetchItem['name'];
$iprice = $fetchItem['price'];
$idesc = $fetchItem['description'];
$iimage = $fetchItem['image'];
$istock = $fetchItem['in_stock'];
if(isset($_POST['update']))
{
$name = mysqli_real_escape_string($conn, $_POST['pname']);
$cost = mysqli_real_escape_string($conn, $_POST['price']);
if($cost < 0.01){ $cost = 0.01; }
$desc = mysqli_real_escape_string($conn, $_POST['description']);
$image = mysqli_real_escape_string($conn, $_POST['image']);
$instock = $_POST['stock'];
$queryUpdate = "UPDATE products SET name = '$name', price = '$cost', description = '$desc', image = '$image', in_stock = '$instock' WHERE id = '$product'";
$doUpdate = mysqli_query($conn, $queryUpdate) or die(mysqli_error($conn));
$message = "<h3>Item Updated</h3>";
//update form
$queryItem = "SELECT * FROM products WHERE id = '$product'";
$doItem = mysqli_query($conn, $queryItem) or die(mysqli_error($conn));
$fetchItem = mysqli_fetch_assoc($doItem);
$iname = $fetchItem['name'];
$iprice = $fetchItem['price'];
$idesc = $fetchItem['description'];
$iimage = $fetchItem['image'];
$istock = $fetchItem['in_stock'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Product Edit</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1><?php echo $storeName; ?></h1>
<?php if(isset($message)){ echo "<center>".$message."</center>"; } ?>
<div id="viewCart">
<span id="viewTitle">Edit Product: <?php echo $product; ?></span><a href="admin.php">Back to Admin Panel</a><br><br>
<b>Product Name</b><br>
<form method="post">
<input type="text" class="text" name="pname" value="<?php echo $iname; ?>"><br>
<b>Price USD</b><br>
<input type="text" class="text" name="price" value="<?php echo $iprice; ?>"><br>
<b>Description</b><br>
<textarea class="inputArea" name="description"><?php echo $idesc; ?></textarea><br><br>
<b>Image Link</b> example: http://i.stack.imgur.com/m9uaE.png<br>
<input type="url" class="text" name="image" value="<?php echo $iimage; ?>"><br>
<b>Item In Stock?</b> Marking it "No" will hide the item from visitors<br>
<input type="radio" name="stock" <?php if(isset($istock) && $istock == "1"){ echo "checked"; } ?> value="1">Yes
<input type="radio" name="stock" <?php if(isset($istock) && $istock == "0"){ echo "checked"; } ?> value="0">No <br>
<input type="submit" id="add" name="update" value="Update">
</form>
<br>
</div>
<br>
</body>
</html>