-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddNewProduct.php
More file actions
34 lines (24 loc) · 1.02 KB
/
addNewProduct.php
File metadata and controls
34 lines (24 loc) · 1.02 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
<?php
session_start();
require('db.php');
if (isset($_POST['addNewProduct'])) {
$name = $_POST['name'];
$description = $_POST['description'];
$category_id = $_POST['category'];
$tags = $_POST['tags'];
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_tmp = $_FILES['file']['tmp_name'];
$query = "SELECT category_name FROM categories WHERE id = $category_id";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
$categoryName = $row['category_name'];
$pathToThisCategory = 'images/category/' . $categoryName;
$fullFilePath = $pathToThisCategory . '/' . $file_name;
if (move_uploaded_file($file_tmp, $fullFilePath)) {
$sqlQueryProduct = "INSERT INTO handicrafts (name, description, id_category, file, tags) VALUES ('$name', '$description', '$category_id', '$file_name', '$tags')";
$conn->query($sqlQueryProduct);
header('Location: categories.php?id_category=' . $category_id);
}
}
?>