title: How to delete database row in this php script
body: <p>I have a situation with my php code. What I am currently doing is using the iframe to link the javascript message with the phe script. In the javascript function stopImageUpload, I have stated that if success = 2, then display the cancel message for the file upload.</p>
  
  <p>So what I have tried but failed to do in the php script is to try and state that if the $result = 2 (In other words if success = 2 message appears in javascript), then delete the database row. How can this be done?</p>
  
  <p>Below is the form code:</p>
  
  <pre><code>var $fileImage = $("&lt;form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return imageClickHandler(this);' class='imageuploadform' &gt;" + 
    "Image File: &lt;input name='fileImage' type='file' class='fileImage' /&gt;&lt;/label&gt;&lt;br/&gt;&lt;br/&gt;&lt;label class='imagelbl'&gt;" + 
    "&lt;input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /&gt;&lt;/label&gt;" +     
    "&lt;/p&gt;&lt;p class='imagef1_cancel' align='center'&gt;&lt;label&gt;" + 
    "&lt;input type='button' name='imageCancel' class='imageCancel' value='Cancel' /&gt;&lt;/label&gt;" +
    "&lt;iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'&gt;&lt;/iframe&gt;&lt;/form&gt;");
  </code></pre>
  
  <p>Below is the startImageUpload() function where it starts an file upload and where the cancel button function is stored:</p>
  
  <pre><code>  function startImageUpload(imageuploadform, imagefilename){
      $('.imagef1_cancel').eq(window.lastUploadImageIndex).find(".imageCancel").on("click", function(event) {
        return stopImageUpload(2);
        });     
      return true;
    }
  </code></pre>
  
  <p>Below is the stopImageUpload() function where it displays the cancel message using success and result:</p>
  
  <pre><code>function stopImageUpload(success, imagefilename){
    var result = '';
    if (success == 2){
      result = '&lt;span class="imagecemsg"&gt; The file upload was canceled!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;';
    } else {
      result = '&lt;span class="imageemsg"&gt;There was an error during file upload!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;';
    }         
    return true;   
  }
  </code></pre>
  
  <p>Finally below is the imageupload.php script which is linked to the QandATable.php (The script which contains the code above) using iframe and this is where the database row is suppose to be inserted and deleted from:</p>
  
  <pre><code>    &lt;?php
        session_start();
        ...//connected to DB
        $result = 0;
  
  if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {
      $result = 1;
  
      $imagesql = "INSERT INTO Image (ImageFile) 
      VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
  
      mysql_query($imagesql);
  
  }
      else
        {
  
        $result = 1;
  
          $imagesql = "INSERT INTO Image (ImageFile) 
          VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
  
  mysql_query($imagesql);
  
        }
  
        if ($result == 2) {
          $imagecancelsql = "DELETE FROM Image 
                             WHERE ImageFile = 'ImageFiles/".
                             mysql_real_escape_string($_FILES['fileImage']['name'])."'";
          mysql_query($imagecancelsql);
        }
        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>