File "blog-details.php"

Full Path: /home/quiczmwg/lightspringdigitals.com/admin-20260114051102/database/blog-details.php
File size: 7.33 KB
MIME-type: text/x-php
Charset: utf-8

<?php 
include 'head.php';
include 'header.php';
?>

<body class="skin-default fixed-layout">
    <div id="main-wrapper">
        <?php 
        include 'sidebar.php';
        if (isset($message)) {
            foreach ($message as $message) {
                echo '<div class="message"><span>' . $message . '</span> <i class="fas fa-times" onclick="this. parentElement.style.display = `none`;"></i> </div>';
            };
        };
        ?>
        
        <div class="page-wrapper">
            <div class="container-fluid">
                <?php include 'nav.php'; ?>
                <div class="container">
                   
                    <!-- DETAILS/DELETE MODAL -->
            <div class=""> 
            <?php
// Assuming you have a database connection established
if (isset($_GET['blog_id'])) {
    $blog_id = $_GET['blog_id'];

    // Fetch blog data from the database based on the provided blog_id
    $query = "SELECT * FROM blog WHERE blog_id = ?";
    
    if ($stmt = $conn->prepare($query)) {
        $stmt->bind_param("s", $blog_id);
        
        if ($stmt->execute()) {
            $result = $stmt->get_result();

            // Check if there are rows in the result set
            if ($result->num_rows > 0) {
                $row = $result->fetch_assoc();
                $categoriesArray = array($row['categories']);
            
?>

                <div class="text-right my-4">
                        <a href="#" data-toggle="modal" data-target="#myModal" class="btn btn-info "><i class="bi bi-pencil-square"></i> Edit</a>
            
                        <a href="blog-controller.php?delete=<?php echo $row['id']; ?>" class="btn btn-danger" onclick="return confirm('are you sure you want to delete this?');"><i class="bi bi-trash3-fill"></i> Delete</a>
                </div>
                <div class=" card">
                    <div class=" card-header">
                        <h3 class="">Manage Blog Details</h3>
                    </div> 
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6">
                                <img src="../blog/<?php echo $row['blog_img']; ?>" class="img-fluid" height="700" alt="">
                            </div>
                            
                            <div class="col-md-3">
                                <h2>BLOG NAME:</h2>
                                <p><?php echo html_entity_decode($row['title']); ?></p>
                            </div>

                            <div class="col-md-3">

                                <h2>Categories:</h2>
                                <p><?php echo html_entity_decode($row['categories']); ?></p>

                                <h2>Description:</h2>
                                <p><?php echo html_entity_decode($row['description']); ?></p>
                            </div>
                     
                    </div>  
                </div>                            
            </div>





        
        

            <!-- The Modal -->
          <div class="modal fade" id="myModal">
            <div class="modal-dialog modal-lg">
              <div class="modal-content">
              
                <!-- Modal Header -->
                <div class="modal-header">
                  <h4 class="modal-title">Manage Services</h4>
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>
                
                <!-- Modal body -->
                <div class="modal-body">
                  <form action="manage-blog-process.php" method="post">

                  <div class="form-group">
                    <input type="text" name="title" placeholder="Enter Blog Title" class="form-control my-2  " required value="<?php echo $row['title']; ?>">
                      <!-- <input type="text" name="p_description" placeholder="Enter the service full description" class="form-control" required> -->

                  </div>
                
                  
                  <div class="form-group">
                      <input type="text" name="sub_title" placeholder="Enter Blog Sub title" class="form-control my-2  " value="<?php echo $row['sub_title']; ?>" required>

                  </div>
                  
                  <div class="form-group">
                      <select class="form-select ps-4 mb-1" aria-label="Default select example" name="categories">
                       
                        <?php
                        // Loop through the categoriesArray and generate options
                        foreach ($categoriesArray as $category) {
                            // Check if the option value matches the one retrieved from the database
                            $selected = ($category == $selectedCategoryFromDatabase) ? 'selected' : '';

                            echo "<option class='option-item' value='$category' $selected>$category</option>";
                        }
                        ?>
                         <option class="option-item " value="Wall art" class="">Wall art</option>
                        <option class="option-item " value="Game" class="">Game</option>
                        <option class="option-item " value="Character" class="">Character</option>
                        <option class="option-item " value="Animal" class="">Animal</option>
                        <option class="option-item " value="Robot" class="">Robot</option>
                        <option class="option-item " value="Fashion" class="">Fashion</option>
                        <option class="option-item " value="Wild Life" class="">Wild Life</option>
                      </select>
                  </div>

                  <div class="form-group">
                      <input type="decimal" name="tags" placeholder="Enter  Blog Tags" class="form-control my-2  " value="<?php echo $row['tags']; ?>" required>

                  </div>
                  
                  <div class="form-group">
                    <input type="file" name="blog_img" accept="image/png, image/jpeg, image/jpg" class="form-control-file box" value="<?php echo $row['blog_img']; ?>" >
                  </div>
                  <div class="form-group">
                    <textarea name="description" id="" cols="30" rows="15" class="form-control my-2  "><?php echo $row['description']; ?></textarea>
                  </div>

                <!-- Modal footer -->
                <div class="modal-footer">
                <button type="submit" name="aaddblogUpdate"  class="btn btn-success bg-warn">Update</button>
                  <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                </div>
                </form>
              </div>
            </div>
        </div> 
        </div> 
      </div>
    </section>
            </div>
          </div>
        </div>
        <?php } else {
                echo "No blog found for the provided blog_id.";
            }

            // Close the result set
            $result->close();
        } else {
            echo "Error executing the query: " . $stmt->error;
        }

        // Close the prepared statement
        $stmt->close();
    } else {
        echo "Error preparing the query: " . $conn->error;
    }
} else {
    echo "No blog_id provided in the URL.";
}
 ?>
    <?php
    include 'footer.php';
    ?>