<?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");
}
}
?>
0 Comments