-->

Guide to Remove Notes with Bootstrap Confirm Capital using Script PHP & MySQL Versi Berga

this tutorial you will learn how to apply delete records with Bootstrap confirmation capital using PHP and MySQL. The use of the default JavaScript confirmation modal is common on the website to make sure it deletes the recording or not. Bootstrap asserts the dialog is a very subtle UI and better than the default JavaScript confirmation dialog. So here we have covered the functionality to display records with PHP and MySQL and then handles the deletion of records with Bootstrap Confirm Capital using the BootBox Bootstrap Modal plugin.

So let's start coding.

Steps1: Create a MySQL Database Table

For this tutorial, we have used the MySQL database table "employees" to display employee records. So we will use the code below to create the table.

CREATE TABLE IF NOT EXISTS `employee` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', `employee_name` varchar(255) NOT NULL COMMENT 'employee name', `employee_salary` double NOT NULL COMMENT 'employee salary', `employee_age` int(11) NOT NULL COMMENT 'employee age', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='datatable demo table' AUTO_INCREMENT=11 ;


Now we will import employee data using below queries

INSERT INTO `employee` (`id`, `employee_name`, `employee_salary`, `employee_age`) VALUES (1, 'Tiger Nixon', 3208000, 61), (2, 'Garrett Winters', 170750, 63), (3, 'Ashton Cox', 86000, 66), (4, 'Cedric Kelly', 433060, 22), (5, 'Airi Satou', 162700, 33), (6, 'Brielle Williamsons', 372000, 61), (7, 'Herrod Chandler', 137500, 59), (8, 'Rhona Davidson', 327900, 55), (9, 'Colleen Hurst', 205500, 39), (10, 'Sonya Frost', 103600, 23);

Steps2: Create MySQL Database Connection

We will create db_connect.php PHP file to make connection with MySQL database.



$servername = "localhost";
$username = "root";
$password = "";
$dbname = "phpzag_demos";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
?>


Guide to Remove Notes with Bootstrap Confirm Capital using  Script PHP & MySQL Versi Berga




Steps3: Includes Bootstrap, jQuery and JavaScript files


In this tutorial, we have created a PHP index.php file and include all required library files (Bootstrap, jQuery and Bootbox plugins to confirm capital) and CSS files in the head tag. In this tutorial, we have created HTML using Bootstrap. The deleteRecords.js JavaScript file handles the deletion of employee records on click events by creating an Ajax request.









Guide to Remove Notes with Bootstrap Confirm Capital using  Script PHP & MySQL Versi Berga




Steps4: List Employee Records

Now in index.php, we will display employee records from MySQL database table with delete button to delete records.




Employee Name


Actions




$sql = "SELECT id, employee_name, employee_salary, employee_age FROM employee LIMIT 5";
$resultset = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
while( $rows = mysqli_fetch_assoc($resultset) ) {
?>







}
?>



Steps5: Delete Records with jQuery Ajax

Now in deleteRecords.js JavaScript file, we will handle to get clicked employee id if user click on Delete button in confirm dialog and make Ajax request to server deleteRecords.php to delete clicked employee records from MySQL database table employee.

$(document).ready(function(){
$('.delete_employee').click(function(e){
e.preventDefault();
var empid = $(this).attr('data-emp-id');
var parent = $(this).parent("td").parent("tr");
bootbox.dialog({
message: "Are you sure you want to Delete ?",
title: " Delete !",
buttons: {
success: {
label: "No",
className: "btn-success",
callback: function() {

$('.bootbox').modal('hide');
}
},
danger: {
label: "Delete!",
className: "btn-danger",
callback: function() {
$.ajax({
type: 'POST',
url: 'deleteRecords.php',
data: 'empid='+empid
})
.done(function(response){
bootbox.alert(response);
parent.fadeOut('slow');
})
.fail(function(){
bootbox.alert('Error....');
})
}
}
}
});
});
});



Steps6: Delete Records from MySQL Database

Now finally in deleteRecords.php, we will delete employee record from MySQL database table.


include_once("db_connect.php");

if($_REQUEST['empid']) {
$sql = "DELETE FROM employee WHERE id='".$_REQUEST['empid']."'";
$resultset = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
if($resultset) {
echo "Record Deleted";
}
}

?>

Also Source Code Project More : 

NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post
NEXT ARTICLE Next Post
PREVIOUS ARTICLE Previous Post
 

Delivered by FeedBurner

-->