旧图片缺失

So I have "staff" table in database i.e. StaffName, StaffAddress and StaffProfilePicture etc. Updating works fine on name, address but not the picure. The old picture seems to be missing from the database eventhough I don't upload a new one.

    if(isset($_POST['submit'])){

        $target_dir = "images/staff/";
        $target_dir = $target_dir . basename($_FILES["new_profilepicture"]["name"]);
        $uploadOk=1;

        if (file_exists($target_dir . $_FILES["new_profilepicture"]["name"])) {
        //echo "Sorry, file already exists.";
        $uploadOk = 0;
    }
        if ($uploadOk==0) {
        //echo "Sorry, your file was not uploaded.";
    } 
    else { 
    if (move_uploaded_file($_FILES["new_profilepicture"]["tmp_name"], $target_dir)) {
        $imageup = $target_dir;
        //echo "<img src='" . $imageup . "' />";
    } else {
        //echo "Sorry, there was an error uploading your file.";
    }
}
        $_var1 = $_POST['new_name'];
        $_var2 = $_POST['new_email'];
        $_var3 = $_POST['new_password'];
        $_var4 = $_POST['new_contactno'];
        $_var5 = $_POST['new_icno'];
        $_var6 = $_POST['new_address'];
        $_var7 = $_POST['new_status'];
        $_var8 = $imageup;

        $query1 =   $mysqli->query("UPDATE staff
                            SET StaffName='$_var1', StaffEmail='$_var2', StaffPassword='$_var3', StaffContactNo='$_var4', StaffICNo='$_var5', StaffAddress='$_var6', StaffStatus='$_var7', StaffProfilePicture='$_var8'
                            WHERE StaffID='$staffID'");

        $success = mysql_query($query1);//is mysql query working?

            if($success){
                //$oldprofilepicture = $staff['StaffProfilePicture'];
                //if(file_exists($oldprofilepicture)){
                    //unlink($oldprofilepicture);//delete now
            echo "success";
            header('location:staff_profile.php');
            die;
            }else{
            echo "failed";
            }
        }

Below is the HTML form for the picture

<tr>
    <td width="170">Old Profile Picture:</td>
    <td><img src="<?php echo $profilepicture ?>" width="100" height="80" /><br><br>
        <input type="file" name="new_profilepicture" />
</tr>

How can I make the old/existed picture stay?

On your query you have:

StaffProfilePicture='$_var8'

so it still updates the database and since $imageup is empty/undefined so is $_var8 and it will update the database with empty value.

So add an if condition:

$_var8 = $imageup;

if($_var8 != '') {
    $query1 =   $mysqli->query("UPDATE staff SET StaffName='$_var1', StaffEmail='$_var2', StaffPassword='$_var3', StaffContactNo='$_var4', StaffICNo='$_var5', StaffAddress='$_var6', StaffStatus='$_var7', StaffProfilePicture='$_var8' WHERE StaffID='$staffID'");
} else {
    $query1 =   $mysqli->query("UPDATE staff SET StaffName='$_var1', StaffEmail='$_var2', StaffPassword='$_var3', StaffContactNo='$_var4', StaffICNo='$_var5', StaffAddress='$_var6', StaffStatus='$_var7' WHERE StaffID='$staffID'");
}

or you can do it other ways but that's where your problem is that you're losing your old image. Hope it helps.

Cheers.