<?php 
session_start();
include 'inc/dbcon.php';


$user = $_POST['user'];
if(strlen($_FILES['image']['name']) > 0){
	$imgdata = "select * from admin where username='$user'" ;
$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 admin SET image='$file' where username='$user'";
 if (mysqli_query($con,$sqldata)) {
	$_SESSION['msg_scs'] = 'Image Updated...';
	header("location: profile.php");
} 
else {
	$_SESSION['msg_err'] = 'Something Went Wrong Try Later..';
	header("location: profile.php");
}

}
?>