-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgallery_edit.php
More file actions
94 lines (80 loc) · 3.37 KB
/
Copy pathgallery_edit.php
File metadata and controls
94 lines (80 loc) · 3.37 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
$title = "Edit Post";
include "./includes/header.php";
include "./confing.php";
?>
<?php
session_start();
if (isset($_GET['editId'])) {
$id = $_GET['editId'];
}
if (isset($_POST['update'])) {
$id = htmlspecialchars($_POST["edit_id"]);
$title = htmlspecialchars($_POST["title"]);
$description = htmlspecialchars($_POST["description"]);
if ($_FILES['file']['name']) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileType = $file['type'];
$fileTmpName = $file['tmp_name'];
$fileError = $file['error'];
$fileSize = $file['size'];
$fileExt = explode(".", $fileName);
$fileActualExt = strtolower($fileExt[1]);
$allowedFileType = ["png", 'jpg', 'jpeg'];
if (in_array($fileActualExt, $allowedFileType)) {
$newFileName = $fileExt[0] . "." . $fileActualExt;
move_uploaded_file($fileTmpName, "./upload/$newFileName");
$query = "UPDATE gallery
SET title = '$title', description= '$description' , image= '/upload/$newFileName'
WHERE id = {$id}";
$result = mysqli_query($db, $query);
if ($result) {
header("Location:gallery.php");
} else {
$error["result"] = "please choose valid image (png, jpg, jpeg)";
}
}
} else {
$query = "UPDATE gallery
SET title = '$title', description= '$description'
WHERE id = {$id}";
$result = mysqli_query($db, $query);
if ($result) {
header("Location:gallery.php");
}
}
}
$query1 = "SELECT * from gallery WHERE id = {$id}";
$result = mysqli_query($db, $query1);
$data = mysqli_fetch_assoc($result);
?>
<?php if (isset($_SESSION["login"])) : ?>
<div class="container">
<div class="row my-5 justify-content-center">
<div class="col-md-8 bg-white p-3 rounded">
<form class=" p-4 rounded" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>">
<h3 class="mb-4">Edit Gallery</h3>
<?php if (isset($_POST["add"])) {
echo "<p class='text-danger'>" . $error['result'] . "</p>";
} ?>
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" name="title" id="title" value="<?php echo $data['title'] ?>" placeholder="post title">
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" name="description" id="description" rows="4"><?php echo $data['description'] ?></textarea>
</div>
<div class="mb-3">
<label for="file" class="form-label">Choose Post Image</label>
<input class="form-control" type="file" name="file" id="file">
</div>
<input type="text" hidden value='<?php echo $data["id"] ?>' name="edit_id">
<button type="submit" name="update" class="btn btn-outline-primary mb-3">Edit</button>
</form>
</div>
</div>
</div>
<?php endif; ?>
<?php include "includes/bottom.php" ?>