I have a problem when the user has clicked on the "Cancel" button. When the user clicks on the "Cancel" button, I want it to delete a row in the database by navigating to the cancelimage.php page. But it is not deleting the database row of the file which has been uploaded but then canceled. By looking at the code below, why is it not deleting the row from the database and how can it be coded so that it does?
Below is the startImageUpload() function where it starts uploading and where the cancel button function is featured:
function startImageUpload(imageuploadform){
...
$(".imageCancel").on("click", function(event) {
var image_file_name = $(this).attr('image_file_name');
jQuery.ajax("cancelimage.php" + image_file_name)
.done(function(data) {
$(".imagemsg" + _cancelimagecounter).html(data);
});
return stopImageUpload();
});
return true;
}
Below is the cancelimage,php page where it is suppose to delete a row from the database?
<?php
$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect('localhost',$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$image_file_name = $_GET["fileImage"]["name"];
echo "File Upload was Canceled";
$imagecancelsql = "DELETE FROM Image
WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($image_file_name)."'";
mysql_query($imagecancelsql);
mysql_close();
?>
Below is the php script (imageupload.php) where it inserts a database row:
<?php
session_start();
$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect('localhost',$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$result = 0;
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);
mysql_close();
?>