-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsell_validation.php
61 lines (49 loc) · 2.02 KB
/
sell_validation.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
<?php
function generateRandomNumber()
{
$min = 100000;
$max = 999999;
return mt_rand($min, $max);
}
$pro_name = $pro_image = $pro_desc = $pro_price = $pro_quantity = $address = $phone_num = "";
$pro_id = generateRandomNumber();
$target_dir = "Product_images/"; // Specify the target directory for storing the uploaded images
$target_file = $target_dir . basename($_FILES["p_image"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$pro_name = $_POST["p_name"];
$pro_desc = $_POST["p_desc"];
$pro_price = $_POST["p_price"];
$pro_quantity = $_POST["p_quantity"];
$pro_category = $_POST["p_category"];
$name = $_POST["name"];
$address = $_POST["address"];
$phone = $_POST["phone"];
$check = getimagesize($_FILES["p_image"]["tmp_name"]);
if ($check !== false) {
$uploadOk = 1;
} else {
$uploadOk = 0;
}
// Move the uploaded file to the target directory
if ($uploadOk == 1) {
if (move_uploaded_file($_FILES["p_image"]["tmp_name"], $target_file)) {
// Insert the file details into the database
$pro_image = $target_file;
require_once 'conn.php';
$sql = "select Product_ID from products where Product_ID = '$pro_id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
do {
$pro_id = generateRandomNumber();
} while ($result->num_rows > 0);
}
$sql = "INSERT INTO `products`(`Product_ID`, `Product_Name`, `Image`, `Description`, `Price`, `Quantity`, `Category`, `Seller_Name`, `Address`, `Phone_Number`) VALUES ('$pro_id','$pro_name','$pro_image','$pro_desc','$pro_price','$pro_quantity','$pro_category','$name','$address','$phone')";
$result = $conn->query($sql);
header('Location: sell.php?action=success');
}
} else {
header('Location: sell.php?action=invalid-image');
}
}