<?php 
session_start();
include 'lib/dbcon.php';
if (isset($_REQUEST['update'])) {
$id = $_POST['id'];
 $title = $_POST['heading'];
$content = $_POST['content'];
if(strlen($_FILES['image']['name']) > 0){
	$imgdata = "select * from management 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 management 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 management set heading='$title',content='$content' where id='$id'";
if(mysqli_query($con,$data)){
$_SESSION['msg_scs'] = 'Data Updated...';
	header("location: management.php");
}
else{
	$_SESSION['msg_err'] = 'Something Went Wrong Try Later..';
	header("location: management.php");
}


	
}

}


?>