Can a database row be deleted if a file is moved into a different destination?
<p>I have a file which can possibly be moved into either 2 places depending on which button the user clicked on a seperate page:</p>

<p>At the moment I have stated if the the file moves into 'ImageFiles' folder then move the folder and insert a database row.</p>

<p>But I want to also include that if the file hasn't been uploaded into 'ImageFiles' folder, then delete database row using this code below:</p>

<pre><code>$imagecancelsql = "DELETE FROM Image 
                   WHERE ImageFile = 'ImageFiles/".
                   mysql_real_escape_string($_FILES['fileImage']['name'])."'";
mysql_query($imagecancelsql);
</code></pre>

<p>Is this possible to do and if so how can it be written in the current if/else statement I have in the php script?</p>

<p>Below is php script:</p>

<pre><code>&lt;?php

session_start();


...//connect to DB

$result = 0;

if( is_file("ImageFiles/".$_FILES['fileImage']['name'])) {
$parts = explode(".",$_FILES['fileImage']['name']);
$ext = array_pop($parts);
$base = implode(".",$parts);
$n = 2;

while( is_file("ImageFiles/".$base."_".$n.".".$ext)) $n++;
$_FILES['fileImage']['name'] = $base."_".$n.".".$ext;

    move_uploaded_file($_FILES["fileImage"]["tmp_name"],
    "ImageFiles/" . $_FILES["fileImage"]["name"]);
    $result = 1;

    $imagesql = "INSERT INTO Image (ImageFile) 
    VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";

    mysql_query($imagesql);

}
    else
      {
      move_uploaded_file($_FILES["fileImage"]["tmp_name"],
      "ImageFiles/" . $_FILES["fileImage"]["name"]);
      $result = 1;

        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";

mysql_query($imagesql);

      }
</code></pre>
