-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateStoreProcess.php
More file actions
78 lines (66 loc) · 2.72 KB
/
updateStoreProcess.php
File metadata and controls
78 lines (66 loc) · 2.72 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
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
78
<?php
session_start();
include "connection.php";
$email = $_SESSION["shop"]["shop_email"];
// Retrieve inputs
$storeName = $_POST["n"];
$storeEmail = $_POST["e"];
$storeMobile = $_POST["m"];
$storeAddress = $_POST["a"];
// Validate inputs
if (empty($storeName)) {
echo "Please insert Your Store Name";
} else if (empty($storeMobile)) {
echo "Please insert Your Store Mobile";
} else if (strlen($storeMobile) != 10) {
echo "Mobile number must have only 10 digits";
} else if (!preg_match("/^07[0-8][0-9]{7}$/", $storeMobile)) {
echo "Invalid Mobile Number";
} else if (empty($storeAddress)) {
echo "Please insert your store Address";
} else {
// Check if the shop exists
$shop_rs = Database::search("SELECT * FROM `shop` WHERE `shop_email` = '$email'");
if ($shop_rs->num_rows == 1) {
// Update shop details
Database::iud("UPDATE `shop`
SET `shop_name` = '$storeName',
`shop_email` = '$storeEmail',
`contact` = '$storeMobile',
`shop_address` = '$storeAddress'
WHERE `shop_email` = '$email'");
// Check if a file is uploaded
if (isset($_FILES["i"]) && $_FILES["i"]["error"] === UPLOAD_ERR_OK) {
$image = $_FILES["i"];
$imageExtension = pathinfo($image["name"], PATHINFO_EXTENSION);
// Allowed image extensions
$allowedExtensions = ["jpg", "png", "jpeg", "svg"];
if (in_array(strtolower($imageExtension), $allowedExtensions)) {
// Generate a unique file path
$filePath = "img/store_images/" . $storeName . "_" . uniqid() . "." . $imageExtension;
// Move the uploaded file
move_uploaded_file($image["tmp_name"], $filePath);
// Check if a shop image already exists
$image_rs = Database::search("SELECT * FROM `shop_image` WHERE `shop_shop_email` = '$email'");
if ($image_rs->num_rows == 1) {
// Update existing image path
Database::iud("UPDATE `shop_image`
SET `image_path` = '$filePath'
WHERE `shop_shop_email` = '$email'");
} else {
// Insert new image path
Database::iud("INSERT INTO `shop_image` (`image_path`, `shop_shop_email`)
VALUES ('$filePath', '$email')");
}
echo "success";
} else {
echo "Invalid image type. Allowed types are: JPG, PNG, JPEG, SVG.";
}
} else {
echo "No image selected or an error occurred while uploading.";
}
} else {
echo "Invalid user.";
}
}
?>