PHP MySQL confirmation box before delete record using jquery ajax

Today, i will show you how to add confirm box before delete item in php. It’s always necessary to confirm yes or no about that removing record. If we confirm before delete records it’s safe to client that delete right records. So in this post i will show you how to add confirmation popup of jquery and remove item dynamically.

Here, i have simple create “users” table and then list all users with table using bootstrap. Using bootstrap it looks better layout. So added delete button, when user will click on delete button confirm box open and ask to remove or not current item. after click on yes fire ajax and remove the current record.

I simple create following three files for makeing this example:


1. db_config.php
2. index.php
3. delete.php

So, you have to simple follow bellow few step to get this example, after end of the tutorial you will get bellow layout:

Step 1 : Create New Table

In this step, we require to create new database and users table on that database. So i simply create my database and “users” table like as bellow sql query:


CREATE TABLE `users` (
`id` int(10) UNSIGNED NOT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Step 2 : Create db_config.php file

In second step, we will create database configuration file, it is call db_config.php. In this file we have to add our database details like username, password, database and hostname. So let’s create config.php file and put bellow code.



Step 3 : Create index.php File

Here, we will create index.php file and write code of listing users data and import jquery files. I used cdn for all js and css file so don’t need to download it locally. So let’s just put bellow code on index.php file.

 

PHP mysql confirmation box before delete record using jquery ajax

 

 

PHP mysql confirmation box before delete record using jquery ajax

Name Email Action

 

 

Step 4 : Create delete.php File

In last step, we will create delete.php file and write code of delete mysql database table. In this way you can delete record from mysql query. So let’s just create delete.php file and put bellow code:



echo 'Deleted successfully.';
}

?>

Now you can simply run above full example from index.php file.

I hope it can help you…

Leave a Reply

Your email address will not be published. Required fields are marked *