如何替换PHP中的现有图像?

I'm having a difficulty on how to replace the image on my folder and database. I don't have the slightest idea on how to code it. Can somebody help me?

My code is like this.

if ((($_FILES["prodImage"]["type"] == "image/gif")
|| ($_FILES["prodImage"]["type"] == "image/jpeg")
|| ($_FILES["prodImage"]["type"] == "image/pjpeg")
|| ($_FILES["prodImage"]["type"] == "image/jpg")
|| ($_FILES["prodImage"]["type"] =="image/png"))
&& ($_FILES["prodImage"]["size"] < 2000000))
{
    if (file_exists("product_images/" . $_FILES["prodImage"]["name"]))
        {
        ?>
            <script language="javascript"> 
            alert("<?php echo $_FILES["prodImage"]["name"] . " already exists. ";?>");
            window.history.back();
            </script>
        <?php
        }
        else
        {
            move_uploaded_file($_FILES["prodImage"]["tmp_name"],
            "product_images/" .$_FILES["prodImage"]["name"]);
            $im = $_FILES["prodImage"]["name"];


            $qry = "INSERT INTO products(productID, productName, productDesc, price, image, product_status, product_type) VALUES(null,'$prodName','$prodDesc','$price','$im','$category', '$prodtype')";
            $result = @mysql_query($qry);
            //Check whether the query was successful or not


    }
}

Basically you should check if the file already exists. If it exists: delete or overwrite it, then use an UPDATE statement instead of the INSERT INTO. If it does not exist: Save the file and use the INSERT INTO statement just like before.