Image edit and mysql
<p>I have a simple table for reference page:
  id    name    description     image</p>

<p>In reference.php, A form upload image to a folder and save image's name in image section. 
In reference.php?action=edit page I want to edit the image. What is correct way to edit? Uploading another image and update the table? 
Functions:  </p>

<pre><code>function editRef() {
    ?&gt;
    &lt;?php 
     $row = queryWithID('reference');
     EpUpload();
     ?&gt;
    &lt;div class="form"&gt;
        &lt;form action="" method="post" enctype="multipart/form-data"&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;label&gt;Name&lt;/label&gt;&lt;/li&gt;
          &lt;li&gt;&lt;input name="refname" type="text" class="inp" value="&lt;?php echo $row['name']; ?&gt;" /&gt;&lt;/li&gt;
          &lt;li&gt;&lt;label&gt;Description&lt;/label&gt;&lt;/li&gt;
          &lt;li&gt;&lt;textarea name="reftext" cols="" rows=""&gt;&lt;?php echo $row['description']; ?&gt;&lt;/textarea&gt;&lt;/li&gt;
          &lt;li&gt;&lt;label&gt;Image&lt;/label&gt;&lt;/li&gt;
          &lt;li&gt;&lt;input name="refile" type="file" /&gt;&lt;/li&gt;
          &lt;li&gt;&lt;label&gt;Sıra&lt;/label&gt;&lt;/li&gt;
          &lt;li&gt;&lt;input name="reforder" type="text" class="inp"/&gt;&lt;/li&gt;
          &lt;li&gt;&lt;input name="refsubmit" type="submit" value="Edit"  class="int"/&gt;&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/form&gt;
&lt;/div&gt;
    &lt;?php
}

function EpUpload() {
    $refsubmit = safe_mysql('refsubmit');
    $reftext     = safe_mysql('reftext');
    $refname     = safe_mysql('refname');
    $reforder    = safe_mysql('reforder');
    $refile    = $_FILES['refile']['name'];
    $tmp         = $_FILES['refile']['tmp_name'];
    $fileType  = $_FILES['refile']['type'];
    $path      = SITE_ROOT."uploads/images/";


    if($refsubmit){
    $require_fields = array("$reftext","$refname", "$reforder");
        if(checkBlank($require_fields)){
            echo "&lt;p class='not'&gt;&lt;span&gt;Please fill all inputs!&lt;/span&gt;&lt;/p&gt;";
        }
        else{
      move_uploaded_file($tmp, $path.$refile);
        $query = "UPDATE reference SET name = '$refname', order='$reforder' description = '$reftext', image = '$refile' WHERE id = $id ";
    $result = mysql_query($sql);
      if(mysql_affected_rows () == 1){
        echo "&lt;p class='ok'&gt;&lt;span&gt;rBlah blah&lt;/span&gt;&lt;/p&gt;";
    }
    else{
        echo mysql_error();
    }
        }
}
}

function queryWithID($table){
if(is_numeric($_GET['id'])){ $id = mysql_real_escape_string($_GET['id']);}
$sql    = "SELECT * FROM $table WHERE id= $id";
$result = mysql_query($sql);
$row    = mysql_fetch_array($result);
return $row ;
 }
</code></pre>

<p>Thanks</p>
