/
/
home
/
u523034047
/
domains
/
badshacric.com
/
public_html
/
admin
Server: in-mum-web1112.main-hosting.eu (62.72.28.111)
You: 216.73.216.52
PHP 8.3.16
Dir:
/home/u523034047/domains/badshacric.com/public_html/admin
Edit:
/home/u523034047/domains/badshacric.com/public_html/admin/edit-post.php
<?php include('conn.php'); session_start(); $message=""; if (!isset($_SESSION['username'])) { header("location:index.php"); exit; } // =============================== // GET BLOG ID // =============================== if (!isset($_GET['id']) || empty($_GET['id'])) { header("location:add-blog.php"); exit; } $id = (int)$_GET['id']; // =============================== // FETCH EXISTING BLOG DATA // =============================== $stmt = $conn->prepare("SELECT * FROM posts WHERE id = ?"); $stmt->bind_param("i", $id); $stmt->execute(); $result = $stmt->get_result(); $post = $result->fetch_assoc(); $stmt->close(); if (!$post) { echo "Blog not found!"; exit; } // =============================== // UPDATE BLOG // =============================== if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = trim($_POST['title']); $slug = trim($_POST['slug']) ?: strtolower(preg_replace('/[^a-z0-9-]+/', '-', $title)); $summary = $_POST['summary']; $content = $_POST['content']; $author = $_POST['author'] ?: 'PlayBro'; $tags = $_POST['tags']; $status = $_POST['status']; // Old image $old_image = $post['featured_image']; $new_image = $old_image; // =========================== // IMAGE UPDATE // =========================== if (!empty($_FILES['featured_image']['name'])) { $filename = time() . "_" . basename($_FILES['featured_image']['name']); $path = "uploads/" . $filename; if (move_uploaded_file($_FILES['featured_image']['tmp_name'], $path)) { // Delete old image if (!empty($old_image) && file_exists("uploads/" . $old_image)) { unlink("uploads/" . $old_image); } $new_image = $filename; } } // =========================== // UPDATE QUERY // =========================== $stmt = $conn->prepare(" UPDATE posts SET title = ?, slug = ?, summary = ?, content = ?, author = ?, tags = ?, featured_image = ?, status = ? WHERE id = ? "); $stmt->bind_param( "ssssssssi", $title, $slug, $summary, $content, $author, $tags, $new_image, $status, $id ); if ($stmt->execute()) { echo "<script>alert('Blog Updated Successfully!'); window.location='add-blog.php';</script>"; exit; } else { echo "<script>alert('Failed to update blog');</script>"; } $stmt->close(); } ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Admin</title> <!-- BOOTSTRAP STYLES--> <link href="assets/css/bootstrap.css" rel="stylesheet" /> <!-- FONTAWESOME STYLES--> <link href="assets/css/font-awesome.css" rel="stylesheet" /> <!-- CUSTOM STYLES--> <link href="assets/css/custom.css" rel="stylesheet" /> <!-- GOOGLE FONTS--> <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' /> </head> <body> <div id="wrapper"> <div class="navbar navbar-inverse navbar-fixed-top"> <?php include ('header.php');?> </div> <!-- /. NAV TOP --> <nav class="navbar-default navbar-side" role="navigation"> <?php include ('menu.php');?> </nav> <!-- /. NAV SIDE --> <div id="page-wrapper" > <div id="page-inner"> <!-- /. ROW --> <hr /> <!-- /. ROW --> <div class="panel panel-primary" data-collapsed="0"> <div class="panel-heading"> <div class="panel-title" > <i class="entypo-plus-circled"></i> Update Post </div> </div> <?php if($message) echo "<p style='color:green'>$message</p>"; ?> <form method="POST" enctype="multipart/form-data"> <label>Title</label> <input type="text" name="title" value="<?php echo $post['title']; ?>" required><br><br> <label>Slug</label> <input type="text" name="slug" value="<?php echo $post['slug']; ?>"> <br><br> <label>Summary</label> <textarea name="summary" rows="3"><?php echo $post['summary']; ?></textarea><br><br> <label>Content</label> <textarea name="content" rows="6" required><?php echo $post['content']; ?></textarea><br><br> <label>Author</label> <input type="text" name="author" value="<?php echo $post['author']; ?>"><br><br> <label>Tags</label> <input type="text" name="tags" value="<?php echo $post['tags']; ?>"><br><br> <label>Status</label> <select name="status"> <option value="published" <?php if($post['status']=='published') echo 'selected'; ?>>Published</option> <option value="draft" <?php if($post['status']=='draft') echo 'selected'; ?>>Draft</option> </select> <label>Featured Image</label> <img src="uploads/<?php echo $post['featured_image']; ?>" width="120"><br> <input type="file" name="featured_image"> <br><br> <button type="submit">Update Blog</button> </form> </div> </div> <div class="panel panel-primary" data-collapsed="0"> <div class="panel-heading"> <div class="panel-title" > <i class="entypo-plus-circled"></i> Status </div> </div> <div class="panel-body"> <div style="overflow-x:auto;"> <div class="col-lg-12 col-md-12"> <div class="table-responsive"> <table class="table"> <thead> <tr> <th>#</th> <th>Image</th> <th>Title</th> <th>Slug</th> <th>Action</th> </tr> </thead> <tbody> <?php $sql = "SELECT id, title, slug, featured_image FROM posts ORDER BY id DESC"; $query = mysqli_query($conn, $sql); $count = 1; while ($row = mysqli_fetch_assoc($query)) { ?> <tr class="info"> <td><?php echo $count++; ?></td> <td> <?php if ($row['featured_image']) { ?> <img src="uploads/<?php echo $row['featured_image']; ?>" height="50" width="50"> <?php } else { ?> <img src="https://via.placeholder.com/50" height="50" width="50"> <?php } ?> </td> <td><?php echo $row['title']; ?></td> <td><?php echo $row['slug']; ?></td> <td> <form method="POST" style="display:inline;"> <input type="hidden" name="id" value="<?php echo $row['id']; ?>"> <button type="submit" name="del" class="btn btn-danger" onclick="return confirm('Are you sure?')"> Delete </button> </form> <a href="edit-post.php?id=<?php echo $row['id']; ?>" class="btn btn-primary"> Edit </a> </td> </tr> <?php } ?> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> </div> </div> <!-- /. PAGE INNER --> </div> <!-- /. PAGE WRAPPER --> </div> <div class="footer"> <?php include ('footer.php');?> </div> <!-- /. WRAPPER --> <!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME--> <!-- JQUERY SCRIPTS --> <script src="assets/js/jquery-1.10.2.js"></script> <!-- BOOTSTRAP SCRIPTS --> <script src="assets/js/bootstrap.min.js"></script> <!-- CUSTOM SCRIPTS --> <script src="assets/js/custom.js"></script> </body> </html>
Ukuran: 8.6 KB