<?php


session_start();

$name = $_SESSION['user_name'];

if (isset($_SESSION['user_name']) or !empty($_SESSION['user_name'])) {

 

}else{

   header("location:../index.php");

}

?>

<?php

include __DIR__.'/config/db_connect.php';

include __DIR__.'/config/functions.php';

$id = $_GET['id'];

$sql_update = "select * from tbl_post where id='{$id}'";

$result_set_update = mysqli_query($con,$sql_update);

$row_update = mysqli_fetch_assoc($result_set_update);

$title_up = $row_update['title'];

$content_up = $row_update['content'];

$title_id = $row_update['id'];

?>

<?php

if ($_SERVER['REQUEST_METHOD']== 'POST') {

if(isset($_POST['submit']) or !empty($_POST['submit'])) {


$title = isset($_POST['title'])?$_POST['title']:NUll;

$id = isset($_POST['id'])?$_POST['id']:NUll;

$content = isset($_POST['content'])?$_POST['content']:NUll;

//sanatise title and content

$title = sanatise($title);

$content = sanatise_text($content);

//get date and time zone in india

$date = date_default_timezone_set("Asia/Kolkata");

$date = date("Y-m-d");

$time = date("h:i:s");

//convert title to slug

$slug =strtolower(implode("-",explode(" ",$title)));

//check slug allreday exists

$serch_title = "select title from tbl_post where id = '{$id}'";

$title_result = mysqli_query($con,$serch_title);

//slug_count

$title_count = mysqli_num_rows($title_result);

//check slug number of rows is present

if($title_up==$title) {


echo "No Change in Post !";

}else{

$sql_update ="UPDATE tbl_post SET title='$title',slug='$slug',content='$content',date='$date',time='$time' where id='$id'";

$result_up = mysqli_query($con,$sql_update);

//$row_count1 = mysqli_affected_rows($con);


if($result_up){


echo "<script>";

echo "window.alert('Post updated Successfully');";

echo "location.replace('../show_post');";

echo "</script>";


}else{


echo "<script>";

echo "window.alert('Post not updated');";

echo "</script>";

}

}

}else{

header("location:create_post1.php");

}

}

?>

<!DOCTYPE html>

<html lang="en">

  <head>

    <meta charset="utf-8">

    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>CREATE POST</title>

    <meta content="" name="descriptison">

    <meta content="" name="keywords">

    <!-- Favicons -->

    <base href="<?php

    $webpath = "http://localhost/Dblog/";

    echo "{$webpath}"; ?>">

    <link href="assets/img/favicon.png" rel="icon">

    <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">

    <!-- Google Fonts -->

    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Montserrat:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

    <!-- Vendor CSS Files -->

    <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <link href="assets/vendor/icofont/icofont.min.css" rel="stylesheet">

    <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">

    <link href="assets/vendor/venobox/venobox.css" rel="stylesheet">

    <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">

    <link href="assets/vendor/owl.carousel/assets/owl.carousel.min.css" rel="stylesheet">

    <link href="assets/vendor/aos/aos.css" rel="stylesheet">

    <!-- Template Main CSS File -->

    <link href="assets/css/style.css" rel="stylesheet">

    <!-- =======================================================

    * Template Name: Bootslander - v2.1.0

    * Template URL: https://bootstrapmade.com/bootslander-free-bootstrap-landing-page-template/

    * Author: BootstrapMade.com

    * License: https://bootstrapmade.com/license/

    ======================================================== -->

  </head>

  <body>

    

    <section class="form-body">

      <div class="container ">

        <div class="form-div">

          <form action="" method="post">

            <div class="post_title">

              <input type="text" class="form-control" name="title" value="<?php echo $title_up; ?>" placeholder="title" required="">

              <input type="hidden"  name="id" value="<?php echo $title_id; ?>">

              <br>

              <textarea class="form-control" name="content" required="" ><?php echo $content_up; ?>

              </textarea>

              <br>

              

              <div class="btn">

                <center>

                

                <input type="submit" class="form-control btn1" name="submit" value="Add Post">

                

                </center>

              </div>

            </div>

          </form>

        </div>

      </div>

    </section>

    <a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>

    <div id="preloader"></div>

    <!-- Vendor JS Files -->

    <script src="assets/vendor/jquery/jquery.min.js"></script>

    <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <script src="assets/vendor/jquery.easing/jquery.easing.min.js"></script>

    <script src="assets/vendor/php-email-form/validate.js"></script>

    <script src="assets/vendor/venobox/venobox.min.js"></script>

    <script src="assets/vendor/waypoints/jquery.waypoints.min.js"></script>

    <script src="assets/vendor/counterup/counterup.min.js"></script>

    <script src="assets/vendor/owl.carousel/owl.carousel.min.js"></script>

    <script src="assets/vendor/aos/aos.js"></script>

    <!-- Template Main JS File -->

    <script src="assets/js/main.js"></script>

  </body>

</html>


Post Upate in Php