am trying to build a commenting system with PHP and Mysql. I want to link one post with many comments. So I have a posts table and a comments table. The comments table has a foreign key of post_id which is similar to the posts table id column(which is the primary key in posts table). Once the admin adds a post, the post_id column is inserted with the id of that post. This means that when adding comments, someone has to update the comments table which in my case, it doesn't. Here is the update query.
if(isset($_POST['cmt-btn'])){
if(!empty($_GET['id'])){
$current_id = $_GET['myid'];
echo $current_id;
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
$author = filter_var($_POST['author_name'], FILTER_SANITIZE_STRING);
$post_id = $current_id;
$time = now();
$sql = "UPDATE comments SET comments = '$comment', author = '$author', timeposted = '$time' WHERE post_id = '$current_id'";
$result = $connection->query($sql);
}
The comment table simply fills the empty columns with NULL. I don't seem to trace where the problem is.