I have a series of articles on my webpage. Each of these has a delete form with the same name ("article"). All of my POSTs are done through ajax and work fine! The one problem I have now is that only the last article gets deleted. The hidden input has a value of the row# in the database This is the output I get:
'deletearticle' => 'article=31&article=27&article=21',
Here's my AJAX:
$('.deleteForm').submit(function() {
$.ajax({
url: 'functions/check.php',
type: 'POST',
data: {
deletearticle: $('.deleteForm').serialize()
},
success: function(data){
window.location.reload(true);
}
});
return false;
});
And here's my delete
if (isset($_POST['deletearticle'])) {
parse_str($_POST['deletearticle'], $deletearticle);
$id = $deletearticle['article'];
try {
$stmt = $DB_con->prepare("DELETE FROM articles WHERE id = ".$id." ");
$stmt->execute();
} catch (PDOException $e) {
echo "Fail: ".$e->getMessage();
}
}
EDIT I do know about name=XXX[]. It just doesn't tell me which one in the array was picked by the user to delete.