title: Where to place this if statment in the php script
body: <p>I have a php script below where it adds a database row if a new or existing file is uploaded:</p>
  
  <pre><code>&lt;?php
  session_start();
  ...//connect to DB
  
  $result = 0;
  if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {
      $imagesql = "INSERT INTO Image (ImageFile) 
      VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
  
      mysql_query($imagesql);
  } else {
      $imagesql = "INSERT INTO Image (ImageFile) 
      VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
      mysql_query($imagesql);
  }
  mysql_close();
  ?&gt;
  
  &lt;script language="javascript" type="text/javascript"&gt;window.top.stopImageUpload(&lt;?php echo $result ? 'true' : 'false'; ?&gt;, '&lt;?php echo $_FILES['fileImage']['name'] ?&gt;');&lt;/script&gt;
  </code></pre>
  
  <p>But the problem is that I want to add an if statement below the else statement when $result = 2 so that it deletes a database row. When I try this, then it doesn't insert a database row after uploading a new or existing file. </p>
  
  <pre><code>if ($result = 2){
    $imagecancelsql = "DELETE FROM Image 
    WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($_FILES['fileImage']['name'])."'";
    mysql_query($imagecancelsql);
  }
  </code></pre>
  
  <p>So my question is: how am I supposed to place the if statement above in the php script so that it performs its necessary database update?</p>