im trying to update status field in comments table, but it fails.
this is my form:
<?php
if ($result['comment_status'] == "approved") {
?>
<form action="" method="post">
<input type="hidden" name="comment_id" value="<?php echo $result['comment_id'] ?>">
<button type="submit" name="disapproved" class="btn btn-primary btn-sm">DisApprove
</button>
</form>
<?php
} else {
?>
<form action="" method="post">
<input type="hidden" name="comment_id" value="<?php echo $result['comment_id'] ?>">
<button type="submit" name="approved" class="btn btn-primary btn-sm">Approve</button>
</form>
<?php
}
?>
and this is my php code (query):
if (isset($_POST['comment_id']) && is_numeric($_POST['comment_id']) && $_POST['comment_id'] > 0) {
$comment_id = $_POST['comment_id'];
}
if (isset($_POST['disapproved'])) {
$query = $connection->prepare("UPDATE comments SET comment_status = 'approved' WHERE comment_id = $comment_id");
confirm($query->execute(), "Comment approved successfully", "info");
}
if (isset($_POST['approved'])) {
$query = $connection->prepare("UPDATE comments SET comment_status = 'disapproved' WHERE comment_id = $comment_id");
confirm($query->execute(), "Comment disapproved successfully", "info");
}
i don't know why its not update
if (isset($_POST['disapproved'])) { ... SET comment_status = 'approved' ... }andif (isset($_POST['approved'])) { ... SET comment_status = 'disapproved' ...}. Is that correct?