Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to delete database row in example below?
    primarykey
    data
    text
    <p>I have a cancel button where the user can cancel on a file upload and it will display a cancel message. Now what I want also to happen is that when the user clicks on the Cancel button, it will look up for the file name which has been cancelled in the database and delete the database row. Problem is that it is not deleting the database row at all. How can I get this to happen. At the moment I am using the jpuery.ajax method which you can see in code below.</p> <p>Below is 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' cancel_image_file_name='" + imagefilename + "' value='Cancel' /&gt;&lt;/label&gt;&lt;/form&gt;"); </code></pre> <p>Below is the cancel button function:</p> <pre><code> $('.imagef1_cancel').eq(window.lastUploadImageIndex).find(".imageCancel").on("click", function(event) { var cancel_image_file_name = $(this).attr('cancel_image_file_name'); jQuery.ajax("cancelimage.php?imagefilename=" + cancel_image_file_name) return stopImageUpload(2, cancel_image_file_name); }); </code></pre> <p>Finally below is the cancelimage.php script where the jquery.ajax navigates to, to supposedly be able to delete the the database row containing the file name:</p> <pre><code> &lt;?php ... //I have connected to database $cancel_image_file_name = $_GET["imagefilename"]; $imagecancelsql = "DELETE FROM Image WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($cancel_image_file_name)."'"; mysql_query($imagecancelsql); mysql_close(); ?&gt; </code></pre> <p>UPDATE:</p> <p>Below is what it currently shows when I echo the delete query:</p> <p>Notice: Undefined index: imagefilename in /web/stud/xxx/.../cancelimage.php on line 19 DELETE FROM Image WHERE ImageFile = 'ImageFiles/' </p> <p>Below is the code of the delete function where when the Delete Button is pressed, it will navigate to the deleteimage.php script and delete the database row:</p> <pre><code>function stopImageUpload(success, imagefilename){ $('.listImage').eq(window.lastUploadImageIndex).append('&lt;div&gt;' + htmlEncode(imagefilename) + '&lt;button type="button" class="deletefileimage" image_file_name="' + imagefilename + '"&gt;Remove&lt;/button&gt;&lt;br/&gt;&lt;hr/&gt;&lt;/div&gt;'); $('.listImage').eq(window.lastUploadImageIndex).find(".deletefileimage").on("click", function(event) { var image_file_name = $(this).attr('image_file_name'); jQuery.ajax("deleteimage.php?imagefilename=" + image_file_name) $(this).parent().remove(); }); return true; } </code></pre> <p>Below is deleteimage.php script:</p> <pre><code>&lt;?php //connected to DB $image_file_name = $_GET["imagefilename"]; $imagedeletesql = "DELETE FROM Image WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($image_file_name)."'"; mysql_query($imagedeletesql); mysql_close(); ?&gt; </code></pre> <p>Below is an UPDATE of what the cancel button function now looks like:</p> <pre><code>function startImageUpload(imageuploadform, imagefilename){ $('.imagef1_cancel').eq(window.lastUploadImageIndex).find(".imageCancel").on("click", function(event) { var cancel_image_file_name_ = $(this).attr('css'); var cancel_image_file_name = ''; var style_array = cancel_image_file_name_.split(" "); for(i=0;i&lt;style_array.length;i++){ if(style_array[i].substr(0,2) == "__"){ cancel_image_file_name = style_array[i].slice(2,style_array[i].length-2); } } jQuery.ajax("cancelimage.php?imagefilename=" + cancel_image_file_name) return stopImageUpload(2, cancel_image_file_name); }); return true; } </code></pre> <p>I changed the button input tag to this for cancel button:</p> <pre><code>&lt;input type='button' name='imageCancel' class='imageCancel __"+ imagefilename + "' value='Cancel' /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload