I have a table where each row has an image and some text. Currently, when I update the content without selecting an image, the database field for the image gets cleared out. However, I want to keep the old image if there's no image selected.

How can I accomplish this?

As a note, I know that mysql\_\* functions are deprecated.

```
<?php

include("db/db.php");

$select_db = "select * from aboutus WHERE id=1";
$run_news = mysql_query($select_db);

while ($row = mysql_fetch_array($run_news)) {
    $id = $row['id'];
    $image = $row['image'];
    $content = $row['content'];
}
?>
<div class="box box-primary">
    <div class="box-header with-border">
        <h3 class="box-title">Update About Content</h3>
    </div>
    <!-- /.box-header -->
    <!-- form start -->
    <form role="form" method="post" action="aboutcontent.php?id=1"  enctype="multipart/form-data">
        <div class="box-body">

            <div class="form-group">
                <label for="exampleInputFile">Reselect Image *(H=530px, W=800px)</label>
                <input type="file" name="user_image"  id="exampleInputFile">
            </div>

            <div class="form-group">
                <label >Content</label><br>
                <textarea name="content" class="tinymce" class="form-control" rows="15"><?php echo $content; ?></textarea>
            </div>
        </div>
        <!-- /.box-body -->

        <div class="box-footer">
            <button type="submit" name="update" class="btn btn-primary">Update</button>
        </div>
    </form>
</div>

<?php

include("db/db.php");

// Code for UPDATE button
if (isset($_POST['update'])) {

    $content = $_POST['content'];

    $imgFile = $_FILES['user_image']['name'];
    $tmp_dir = $_FILES['user_image']['tmp_name'];
    $imgSize = $_FILES['user_image']['size'];

    if ($imgFile) {
        $upload_dir = 'images/about/'; // upload directory  
        $imgExt = strtolower(pathinfo($imgFile, PATHINFO_EXTENSION)); // get image extension
        $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
        $userpic = rand(1000, 1000000) . "." . $imgExt;

        if (in_array($imgExt, $valid_extensions)) {
            if ($imgSize < 5000000) {
                unlink($upload_dir . $row['image']);
                move_uploaded_file($tmp_dir, $upload_dir . $userpic);
            }
            else {
                $errMSG = "Sorry, your file is too large it should be less then 5MB";
            }
        }
        else {
            $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
        }
    }
    else {
        // if no image selected the old image remain as it is.
        $userpic = $row['image']; // old image from database
    }

    // if no error occured, continue ....
    $sql = "UPDATE aboutus SET image='$userpic', content='$content' WHERE id=1";
    $query = mysql_query($sql);
    if (!$query) {
        die('Invalid query: ' . mysql_error());
    }
    else {
        echo "<script>alert('Successfully Updated!!!'); window.location='index.php?aboutcontent'</script>";
    }
}

?>

```