showing sweet alert after php database record delete
After I click on a button to delete a single record, I want a sweet alert to display but I don't know if it can be done using php or if it would have to be done using ajax?
This is the button which is in a form with method of "post":
Sweet Alert looks susceptible to using JSON, and PHP can generate the JSON strings. I haven't used it, but that seems like a good way to think about displaying custom messages from the PHP AJAX script.
The instructions appear to be out-of-order in the PHP function. This is why we use error_reporting(E_ALL), so we can catch things that are amiss. $contact_id is undefined in the bind_param() function call.
You might or might not care whether the DELETE query works. If you care (and maybe want to adjust the Sweet Alert output) you would want to test the query for success or failure, and perhaps get the number of rows that were deleted.
Crazy Horse
ASKER
Hi Ray,
My query is working fine and the delete works as it should. I used the W3 schools example as a base whereby they name their variables after they use bind_param. That's the only reason I defined $contact_id after the bind_param. You can check it out here:
Thanks for the tip Ray, I will do it before the bind statement from now.
I did a very basic course on ajax yesterday, so basic that it was only like an hour or something. I was hoping I could try use that knowledge but I think I need to learn some more about ajax and jquery. Anyway, I tried something like this but I get a blank screen as a result.
I think I will leave the ajax part out for now because I actually don't know enough to pull it off. I will have to do some more learning. I will give you points anyway since you advised me that I should be declaring my variables before binding.
Sweet Alert looks susceptible to using JSON, and PHP can generate the JSON strings. I haven't used it, but that seems like a good way to think about displaying custom messages from the PHP AJAX script.
The instructions appear to be out-of-order in the PHP function. This is why we use error_reporting(E_ALL), so we can catch things that are amiss. $contact_id is undefined in the bind_param() function call.
You might or might not care whether the DELETE query works. If you care (and maybe want to adjust the Sweet Alert output) you would want to test the query for success or failure, and perhaps get the number of rows that were deleted.