-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectAdditionPHP.php
More file actions
68 lines (54 loc) · 2.5 KB
/
Copy pathprojectAdditionPHP.php
File metadata and controls
68 lines (54 loc) · 2.5 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
<?php
session_start();
include 'databaseConnection.php';
if ($error != null) {
echo '<p> cant connect to DB<br>';
}
else{
if (!isset($_SESSION['userID'])) {
echo "<script>alert('You are not logged in, please login or sign up first');</script>";
echo "<script>window.location = 'index.php';</script>";
exit();
}
if(!isset($_SESSION['userType']) || $_SESSION['userType']=="client") {
echo "<script> alert('You do not have access to this page');</script>";
echo "<script>window.location = 'clientHomepage.php';</script>";
}
$designerID = $_SESSION['userID'];
}
if (isset($_POST['submitButten1'])) {
if (isset($_POST['name']) && isset($_POST['category']) && isset($_POST['description']) && isset($_FILES["image"]) && $_FILES["image"]["error"] == 0) {
$pName = $_POST['name'];
$description = $_POST['description'];
$category = $_POST['category'];
// Prepare the query to insert data
$queryCat = "SELECT id FROM designcategory WHERE category='$category'";
$result = mysqli_query($connection, $queryCat);
$row = mysqli_fetch_assoc($result);
$categoryID = $row['id'];
// Generate unique filename for the uploaded image
$path_parts = pathinfo($_FILES["image"]["name"]);
$extension = $path_parts['extension'];
$filenewname = $pName . "_" . uniqid() . "." . $extension;
$folder = "images/" . $filenewname;
// Move uploaded file to the desired location
if (move_uploaded_file($_FILES['image']['tmp_name'], $folder)) {
// Insert data into database
$sql = "INSERT INTO designportoflioproject (designerID, projectName, projectImgFileName, description, designCategoryID) VALUES (?, ?, ?, ?, ?)";
$stmt = $connection->prepare($sql);
$stmt->bind_param("isssi", $designerID, $pName, $filenewname, $description, $categoryID);
if ($stmt->execute()) {
echo '<script>alert("Project added successfully.");</script>';
echo '<script>window.location = "designerHomePage.php";</script>';
exit();
} else {
echo '<script>alert("Failed to add project.");</script>';
}
} else {
echo '<script>alert("Failed to upload image.");</script>';
}
} else {
echo '<script>alert("Failed to submit the form.");</script>';
}
}
?>