<?php 
session_start();
include 'lib/dbcon.php';
if (isset($_REQUEST['update'])) {
$id = $_POST['id'];
$author = $_POST['author'];
 $title = $_POST['title'];
$content = $_POST['content'];
if(strlen($_FILES['image']['name']) > 0){
	$imgdata = "select * from blog where id=$id" ;
$query = mysqli_query($con,$imgdata);
$row = mysqli_fetch_array($query);
if($row['image']){
 	unlink($row['image']);
	$filename=$_FILES['image']['name'];
}
$tempname=$_FILES['image']['tmp_name'];
$file="upload/" .$filename;
// print_r($file);
move_uploaded_file($tempname,$file);
 $sqldata = "UPDATE blog SET image='$file' where id=$id";
 if (mysqli_query($con,$sqldata)) {
	$_SESSION['msg_scs'] = 'Data Updated...';
	header("location: management.php");
} 
else {
	$_SESSION['msg_err'] = 'Something Went Wrong Try Later..';
	header("location: management.php");
}

}
else {
$data = "UPDATE blog set author='$author',title='$title',description='$content' where id='$id'";
if(mysqli_query($con,$data)){
$_SESSION['msg_scs'] = 'Data Updated...';
	header("location: blog.php");
}
else{
	$_SESSION['msg_err'] = 'Something Went Wrong Try Later..';
	header("location: blog.php");
}


	
}

}


?>