PHP
OOPs
JavaScript
JQuery
Ajax
Codeigniter
Laravel
MySql
Node.js
Tutorials
C
C++
Json
Codeigniter 4
htaccess
wordpress
react.js
Blogs
Fundamental
Python
Search Your Query
×
--- Select Category ---
PHP
OOPs
JavaScript
JQuery
Ajax
Codeigniter
Laravel
MySql
Node.js
Tutorials
Blogs
Fundamental
Python
Most Popular Tutorials
What is Ajax
How Ajax Work in Php
ajax() and load() function
AJAX get() and post() Method
$.ajax() function
Get data using Ajax call
Load div content on button click
Insert Data in mysql Database
Delete Record
Fetch Data from database
User Registration form
ContactUs form
Change Password
ajax search
insert data usign Serialize
Insert Data without serialize function
User Check Availability
Star rating
Pin check availability
Dynamically Add / Remove input fields in PHP with Jquery Ajax
clear form field after submitting form
Loader show / hide
Javascript and Ajax function
Ajax Programs
Success and Failure message
getJSON Function in ajax
Tutorials Menus
What is Ajax
How Ajax Work in Php
ajax() and load() function
AJAX get() and post() Method
$.ajax() function
Get data using Ajax call
Load div content on button click
Insert Data in mysql Database
Delete Record
Fetch Data from database
User Registration form
ContactUs form
Change Password
ajax search
insert data usign Serialize
Insert Data without serialize function
User Check Availability
Star rating
Pin check availability
Dynamically Add / Remove input fields in PHP with Jquery Ajax
clear form field after submitting form
Loader show / hide
Javascript and Ajax function
Ajax Programs
Success and Failure message
getJSON Function in ajax
Share On Facebook
How to delete data from table using ajax with php and mysql?
Delete Data using Ajax
Table
File name : index.php
CREATE TABLE `posts` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`content` text NOT NULL,
`link` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
config.php
<?php
$host = "localhost"; /* Host name */
$user = "root"; /* User */
$password = ""; /* Password */
$dbname = "tutorial"; /* Database name */
$con = mysqli_connect($host, $user, $password,$dbname);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
File name : html page
<div class='container'>
<table border='1' >
<tr style='background: whitesmoke;'>
<th>S.no</th>
<th>Title</th>
<th>Operation</th>
</tr>
<?php
$query = "SELECT * FROM posts";
$result = mysqli_query($con,$query);
$count = 1;
while($row = mysqli_fetch_array($result) ){
$id = $row['id'];
$title = $row['title'];
$link = $row['link'];
?>
<tr>
<td align='center'><?php echo $count; ?></td>
<td><a href='<?php echo $link; ?>'><?php echo $title; ?></a></td>
<td align='center'>
<span class='delete' id='del_<?php echo $id; ?>'>Delete</span>
</td>
</tr>
<?php
$count++;
}
?>
</table>
</div>
File name : remove.php
<?php
include "config.php";
$id = $_POST['id'];
if($id > 0){
// Check record exists
$checkRecord = mysqli_query($con,"SELECT * FROM posts WHERE id=".$id);
$totalrows = mysqli_num_rows($checkRecord);
if($totalrows > 0){
// Delete record
$query = "DELETE FROM posts WHERE id=".$id;
mysqli_query($con,$query);
echo 1;
exit;
}
}
echo 0;
exit;
Ajax function
File name :
$(document).ready(function(){
// Delete
$('.delete').click(function(){
var el = this;
var id = this.id;
var splitid = id.split("_");
// Delete id
var deleteid = splitid[1];
// AJAX Request
$.ajax({
url: 'remove.php',
type: 'POST',
data: { id:deleteid },
success: function(response){
if(response == 1){
// Remove row from HTML Table
$(el).closest('tr').css('background','tomato');
$(el).closest('tr').fadeOut(800,function(){
$(this).remove();
});
}else{
alert('Invalid ID.');
}
}
});
});
});
Share On Facebook
Previous
Next
Trending Tutorials
PHP
100+ Tutorials
PHP OOPs
80+ Tutorial
Codeigniter
100+ Tutorial
Laravel
100+ Tutorials
NODE.JS
100+ Tutorials
Javascript
100+ Tutorials
Download Live Projects
Review & Rating
0.0
/ 5
0
Review
5
(
0
)
4
(
0
)
3
(
0
)
2
(
0
)
1
(
0
)
Write Review Here
Review
Submit Review
×
Submit
Ittutorial
Ittutorial
Most Popular Tutorials
Dynamically Add / Remove input fields in PHP with Jquery Ajax
insert data usign Serialize
How Ajax Work in Php
Pin check availability
User Registration form
Insert Data in mysql Database
clear form field after submitting form
Fetch Data from database
Load div content on button click
Change Password
Delete Record
getJSON Function in ajax
What is Ajax
ContactUs form
Get data using Ajax call
User Check Availability
Loader show / hide
Insert Data without serialize function
ajax search
Javascript and Ajax function
Important Link
Core php Online Advance Tutorails and video Tutorials.
How to manage Session in php Tutorials.
More .......
upcomming codeigniter and angular js tutorials.
Click here to see More ...
Hello Friend Please Follow & Share Ittutorial.
×
Ittutorial
Please Follow and Share ittutorial.
Ittutorial