First get the previously saved image using the following
and then your code has to like this
<?php <br mode="hold" /?> if(isset($_POST['submit']))
{
$var=$_GET['h_id'];
$file=$_SERVER['DOCUMENT_ROOT'].'myproject/cp/image/'.$img['h_image'];
$var1=$_POST['Title'];
$var2=$_POST['Description'];
$image=$_FILES['imageupload']['name'];
$root=$_SERVER['DOCUMENT_ROOT'].'/myproject/cp/image/';
$file_exts = array("jpg", "bmp", "jpeg", "gif", "png");
$expo=explode(".", $_FILES["imageupload"]["name"]);
$upload_exts = end($expo);
$image = '';
if(isset($_FILES["imageupload"]['name']) && !empty($_FILES["imageupload"]['name']))//check image set or not.
{
if (!(($_FILES["imageupload"]["type"] == "image/gif")|| ($_FILES["imageupload"]["type"] == "image/jpeg")|| ($_FILES["imageupload"]["type"] == "image/png")|| ($_FILES["imageupload"]["type"] == "image/jpg")))
{
$error = "Invalid image";
}else
{
$image= rand(0,9999).'.'.$upload_exts;
move_uploaded_file($_FILES["imageupload"]["tmp_name"],$root.$image);
}
unlink($file);//place unlink function here.
}
else
{
$image = $_POST['old_image'];
}
$sql=mysql_query("UPDATE home SET h_title='".$var1."',h_description='".$var2."',h_image='".$image."' WHERE h_id='".$var."'") or die(mysql_error());
echo "<meta http-equiv=refresh content=\"0; URL=home.php\">";
}
?>
thank u.