php - Deleting a row using AJAX using fadeOut
Get the solution ↓↓↓I am following a tutorial online on AJAX. There is a lecture on how to delete a row from a table without reloading it again.
I added a delete button for each row in my HTML table and I set its id toid="del"
inside a table with anid="myTable"
.
I am trying to delete a row usingAjax
and remove it without refresh with an animationfadeOut()
.
I have thisAjax
script:
$("#myTable #del").click(function()
{
if(confirm("Are you sure you want to delete this row ?"))
{
var id = $(this).closest('tr').attr('id');
var row = $(this).closest('tr');
$.ajax
({
url: 'delete_row.php',
type: 'POST',
data: {dataID: id},
dataType: "text",
success:function(data)
{
console.log(id);
if(data=="deleted")
{
row.fadeOut('slow', function() {$(this).remove();});
}
}
});
}
});
In the console, I see the correct id displayed, but neither does it disappear from the table nor get deleted from database.
Here is the PHP code:
try
{
$id = $_POST['dataID'];
$delete = "DELETE FROM employee WHERE id = :d";
$delStmt = $conn->prepare($delete);
$delStmt->bindValue(":id", $id);
$delStmt->execute();
echo "deleted";
}
catch(PDOException $m)
{
$m->getMessage();
echo "error";
}
The instructor code is working properly, and I can't see where my error is so it isn't working for me. Any help is appreciated.
Answer
Solution:
Bind value hasn't same name in the PDO request
$delete = "DELETE FROM employee WHERE id = :d";
$delStmt->bindValue(":id", $id);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: zsh: command not found: php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.