Jump to content

Recommended Posts

I have a code that calls my retrieve and delete php, both are working properly I can retrieve and delete data from db. I am getting the alert confirming if I want to delete the data which is good as well. But whenever I click YES or NO I am getting the message: Record/s could not be deleted!, instead of Record/s has been deleted! at all even if the record was indeed deleted from the database.

 

I am not posting my retrieve and delete php since they are both working. Just need to correct how the alert message would be displayed.

 

Here's my script that query and delete from db:

 

$(document).ready(function(){
$("#RetrieveList").on('click',function() {
var xid = $('#XiD').val();
var date = $('#Date').val();
$.post('resultgenerator_test.php',{xid:xid, date:date}, function(data){
$("#results").html(data);
});
return false;
});

$("#DeletefromDB").click(function() {
if (confirm("Are you sure you want to delete this Record/s?"))
var id = $('input[name=checkbox]:checked').map(function()
{
return $(this).val();
}).get();
$.post('deletedata_test.php',{id:id}, function(data)
{
$("#result").html(data);
if(data == 'true') {
$('#'+id).remove();alert('Record/s has been deleted!');
}

else {
alert('Record/s could not be deleted!');
}
document.messages.submit();
return false;
});
});
});

First off, the code you have posted is JavaScript and you posted in the PHP forum. << Moving to JS forum >>

 

But, here is the code to determine the message that is displayed:

if(data == 'true')
{
    $('#'+id).remove();
    alert('Record/s has been deleted!');
}
else
{
    alert('Record/s could not be deleted!');
}

You are checking if the variable 'data' is equal to the string value 'true'. I don't see where data is defined (looks like it is passed into the function). But, it is obvious that it is not equal to the string 'true'. Either you meant to be checking if 'data' is the Boolean true

if(data == true)

better yet . . .

if(data)

Or, data doesn't have the value you think it does.

Edited by Psycho
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.