This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-product.php
55 lines (48 loc) · 2.29 KB
/
add-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
<?php
require('config.php');
$target_dir = "assets/img/product-img/";
$target_file = $target_dir . basename($_FILES["productImage"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if (isset($_POST["submitEdit"]) || $_POST["submitAdd"]) {
$check = getimagesize($_FILES["productImage"]["tmp_name"]);
if ($check !== false) {
$uploadOk = 1;
} else {
echo '<script>alert("File is not an image")</script>';
$uploadOk = 0;
}
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo '<script>alert("Sorry, your file was not uploaded.")</script>';
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["productImage"]["tmp_name"], $target_file)) {
if (isset($_POST["submitAdd"])) {
$productName = $_REQUEST['brandName'];
$stockQuantity = $_REQUEST['stockQuantity'];
$manufacturer = $_REQUEST['manufacturerName'];
$category = $_REQUEST['category'];
mysqli_query($con, "ALTER TABLE product AUTO_INCREMENT=11;") or die(mysql_error());
$sql = "INSERT INTO `product`(`ProductName`, `Stocks`, `SupplierID`, `CategoryID`, `IsDeleted`) VALUES ('$productName','$stockQuantity','$manufacturer','$category',b'0');";
$result = mysqli_query($con, $sql) or die(mysql_error());
echo "<script>window.alert('Successfully Added Products!')</script>";
echo "<script>window.location.href = 'admin-products.php'</script>";
} else {
$ProductID = $_REQUEST['prodID'];
$productName = $_REQUEST['brandName'];
$stockQuantity = $_REQUEST['stockQuantity'];
$manufacturer = $_REQUEST['manufacturerName'];
$category = $_REQUEST['category'];
$sql = "UPDATE `product` SET `ProductName`='$productName',`Stocks`='$stockQuantity',`SupplierID`='$manufacturer',`CategoryID`='$category',`IsDeleted`=b'0' WHERE ProductID = '$ProductID'";
$result = mysqli_query($con, $sql) or die(mysql_error());
$url = 'edit-product.php' . "?title=" . $ProductID;
echo "<script>window.alert('Successfully Edited Products!')</script>";
echo "<script>window.location.href = '$url'</script>";
}
} else {
echo '<script>alert("Sorry, there was an error uploading your file.")</script>';
}
}