Home > OS >  Update table column on different page
Update table column on different page

Time:10-16

I am trying to update a column in my table from 0 to 1 when a user clicks on the X button to delete a comment. When I try to delete the comment I get the else statement saying not set.

comment_frame.php:

if ($userLoggedIn == $posted_by) {

    echo $delete_button = "
    <form action='includes/form_handlers/delete_comment.php?comment_id=$comment_idd'
    method='GET' >
    <button name='delete_com' class='delete_comment btn-danger'
    >X " . $comment_id . "</button></form>";
}

delete_comment.php:

if(isset($_GET['comment_id'])) {

    $comment_id = $_GET['comment_id'];
    
} else {

    echo "Not set.";
}

CodePudding user response:

When sending a GET form from the browser, the query string will be composed of the inputs from the form. The compiled query string will replace whatever query string is present in action attribute.

So, when you submit the form, the query string looks like this

?delete_com=

There is no comment_id.

To solve this problem, either send POST request or make the comment_id as a hidden input field.

echo "<form action='includes/form_handlers/delete_comment.php' method='GET' >
 <input type='hidden' name='comment_id' value='".htmlspecialchars($comment_idd, ENT_QUOTES)."' />
 <button name='delete_com' class='delete_comment btn-danger'
 >X ".htmlspecialchars($comment_id, ENT_QUOTES)."</button>
</form>
  • Related