<?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';
if ($_SERVER['REQUEST_METHOD']== 'POST') {
if(isset($_POST['submit']) or !empty($_POST['submit'])) {
$title = isset($_POST['title'])?$_POST['title']:NUll;
$category = isset($_POST['cat'])?$_POST['cat']:NUll;
$name = isset($_POST['name'])?$_POST['name']:NUll;
$content = isset($_POST['content'])?$_POST['content']:NUll;
//sanatise title and content
$title = sanatise($title);
$name = sanatise($name);
//$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_slug = "select * from tbl_post where slug = '{$slug}'";
$slug_result = mysqli_query($con,$serch_slug);
//slug_count
$slug_count = mysqli_num_rows($slug_result);
//check slug number of rows is present
if ($slug_count>0) {
echo "Post Allready Exists";
}else{
$sql = "INSERT INTO tbl_post(title,category,name,slug,content,date,time)values('$title','$category','$name','$slug','$content','$date','$time')";
$result_set = mysqli_query($con,$sql);
if ($result_set){
echo "<script>";
echo "window.alert('Post uploaded Successfully');";
echo "location.replace('show_post');";
echo "</script>";
}
else{
echo "<script>";
echo "window.alert('Post not uploaded')";
echo "</script>";
}
}
}else{
header("location:admin/create_post1.php");
}
}
?>
0 Comments