0

When I submit my form to add a comment reply, the entire div that surrounds the form disappears. The comment still get added to the database but the div just disappears and I have to refresh my page. Any ideas ?

<div id="comment_reply" class="reply_div">

    <form action="reply_comment.php?comment_id=<?php echo $comment_id; ?>"
                        method="POST">

        <input type='hidden' name='comment_id' value="<?php echo $comment_id ?>">

        <textarea name='reply_comment' id='reply_comment'
                             placeholder='Reply...'></textarea>

        <button id="reply_button" name="reply_button">Add</button>

     </form>

    </div>

reply_comment.php:

<?php 

require 'config/connect.php';
$con = new mysqli(...$dbCredentials);

include 'includes/classes/User.php';
include 'includes/classes/Post.php';
include 'includes/classes/Notification.php';

$userLoggedIn = $_SESSION['user_session'];
$comment_id = $_GET['comment_id'] ?? 0;

if (isset($_POST['reply_button'])) {

    if (empty($_POST["reply_comment"])) {

        echo "Reply can't be empty. <a href=".$_SERVER['HTTP_REFERER'].">Try Again</a>";
        exit();
    }

    $reply_body = trim(strip_tags(filter_var($_POST['reply_comment'], 
            FILTER_SANITIZE_STRING)));

    $stmt = $con->prepare("INSERT INTO comment_replies (reply_body, username, comment_id) 
    VALUES (?, ?, ?)");
    $stmt->bind_param("ssi", $reply_body, $userLoggedIn, $comment_id);
    $stmt->execute();

    header($_SERVER['HTTP_REFERER']);
    exit();

}


?>
user13477176
  • 119
  • 6
  • 1
    `exit()` terminates the PHP script. No output is being generated here. What output are you expecting and why? Are you expecting this to be a [redirect](https://stackoverflow.com/questions/768431/how-do-i-make-a-redirect-in-php)?: `header($_SERVER['HTTP_REFERER']);` If so, it's missing the `Location` part of the location header. – David Feb 18 '22 at 20:37
  • Wow can't believe I forgot the `Location` part. Thank you it works. – user13477176 Feb 18 '22 at 20:42

0 Answers0