Reputation: 87
I've been trying to get my delete statement working.
This is how it should work: Whenever I press the delete button 'commentDelete' it should delete the comment, that has the commentID equal to the poster.
But instead, it only deletes the most previous comment, posted by the poster. I'm really confused, and can't figure out why. Here's my code I tried:
function commentsDelete($conn) {
if(isset($_POST['commentsDelete'])){
$commentID = $_POST['commentID'];
$sql = "DELETE FROM comments WHERE commentID='$commentID'";
$result = mysqli_query($conn, $sql);
header("Location: commentpage.php");
}
}
Upvotes: 1
Views: 56
Reputation: 38
Remove the quotes from commentId if it is of numeric type in your database
Upvotes: 2
Reputation: 522161
The commentID is a integer
If the commentID
column is numeric, then you should not be comparing against a quoted text string. Use this instead:
$sql = "DELETE FROM comments WHERE commentID=$commentID";
Upvotes: 4