-
Notifications
You must be signed in to change notification settings - Fork 1
/
editPictureProc.php
38 lines (28 loc) · 1.02 KB
/
editPictureProc.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
<?php
//connect to database
include("database/db_connections.php");
$conn = OpenConn();
//get information from AJAX Request
$pid = $_GET['pid'];
//get the category id from pid and inner join with category table to get the category name
$sql = "SELECT category.category_name FROM product
INNER JOIN category ON product.category_id = category.category_id
WHERE product_id = '$pid'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
//get the category name
$category = $row['category_name'];
$picture_path = "assets/" . $category . "/" . $ppicture;
$target_file = $picture_path . basename($_FILES['ppicture']['name']);
//update product information
$sql2 = "UPDATE product SET picture_path = '$target_file' WHERE product_id = '$pid'";
$result2 = mysqli_query($conn, $sql2);
if ($result2) {
move_uploaded_file($_FILES['ppicture']['tmp_name'], $target_file);
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
//close connection
CloseConn($conn);
header("Location: shoppingAdmin.php");
?>