-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectUpdatePHP.php
More file actions
76 lines (55 loc) · 2.9 KB
/
Copy pathprojectUpdatePHP.php
File metadata and controls
76 lines (55 loc) · 2.9 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
<?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>";
}
}
// Get project ID
if (isset($_GET['projectId'])) {
$id = $_GET['projectId'];
}
if(isset($_POST['submitButten1'])){
$pName = $_POST['pName'];
$category = $_POST['category'];
$categoryIDQuery = mysqli_query($connection, "SELECT id FROM designcategory WHERE category='$category'");
$categoryIDAssoc = mysqli_fetch_assoc($categoryIDQuery);
$categoryID = $categoryIDAssoc['id'];
// Generate unique filename for the uploaded image
if(file_exists($_FILES['image']['tmp_name']) && is_uploaded_file($_FILES['image']['tmp_name'])){
$path_parts = pathinfo($_FILES["image"]["name"]);
$extension = $path_parts['extension'];
$filenewname = $pName . "_" . uniqid() . "." . $extension;
$folder = "images/" . $filenewname;
if (move_uploaded_file($_FILES['image']['tmp_name'], $folder)) {
echo '<script>alert("success to upload image.");</script>'; }
}
else {
$sql = "SELECT projectImgFileName FROM designportoflioproject WHERE id=$id";
$result = mysqli_query($connection, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$filenewname = $row["projectImgFileName"];
}
}
// echo '<script>alert("'.$_POST['pName'].'-'.$filenewname.' '.-$categoryID.' - '.$_POST['description'].' - '.$id.'");</script>';
// Move uploaded file to the desired location
$up = "UPDATE designportoflioproject SET projectName='" . $_POST['pName'] . "', projectImgFileName='" . $filenewname . "', "
. "designCategoryID='" . $categoryID . "', description='" . $_POST['description'] . "' WHERE id =" . $id;
$plsWork = mysqli_query($connection, $up);
if($plsWork){
echo '<script>alert("project was updated successfully.");</script>';
}
} else {
echo '<script>alert("Failed to update project");</script>';
} echo '<script>window.location = "designerHomePage.php";</script>';
?>