php How to link comment sql to the blog sql
<p>first time here and I hope you guys can help me further. </p>

<p>I have created a blogging system to use by mine employees via an admin login system. As well a login system and registration system to use by my customers/viewers. So now I created a comment section for the blog system where people can commenting. The problem is that on each blog the comments are the same. How can link the comments to each blogID?</p>

<pre><code>    &lt;?php
     ob_start();
     require('config.php');

     session_start();
     $id = $_SESSION['user'];

     // if session is not set this will redirect to login page
    if( !isset($_SESSION['user']) ) {
    $buttonlog = 'Login';   
    $smglog = 'Log nu snel in!';
    }if(isset($_SESSION['user'])) {

        $smglog = ' Logout';
        $buttonlog = ' Mijn account';

    }
     // select loggedin users detail
     $sql = mysql_query("SELECT * FROM `userlogin` WHERE `id` = '$id'");
     $userRow = mysql_fetch_array($sql);

     $sql1 = mysql_query("SELECT * FROM `comments`");
     $userRow1 = mysql_fetch_array($sql1);
    ?&gt;


    &lt;?php require('includes/config.php'); 

    $stmt = $db-&gt;prepare('SELECT postID, postTitle, postCont, postDate, imgBackground, imgNewspost FROM blog_posts WHERE postID = :postID');
    $stmt-&gt;execute(array(':postID' =&gt; $_GET['id']));
    $row = $stmt-&gt;fetch();

    //if post does not exists redirect user.
    if($row['postID'] == ''){
        header('Location: ./');
        exit;
    }

    ?&gt;
&lt;?php


function setComments(){
    if(isset($_POST['commentSubmit'])){
        $id = $_POST['id'];
        $username = $_POST['username'];
        $date = $_POST['date'];
        $message = $_POST['message'];

        mysql_query("INSERT INTO `comments` (id, username, date, message) VALUES ('$id','$username', '$date', '$message')");

        }

}
?&gt;
&lt;?php
function deleteComments(){
    if(isset($_POST['DeleteComment'])){
        $id = $_POST['id'];

        mysql_query("DELETE FROM `comments` WHERE `comments`.`id` = '$id'");

    }

} 
?&gt;      
&lt;?php
if (isset($_SESSION['user'])){

echo            "&lt;form method='POST' action='".setComments()."'&gt;
                &lt;input type='hidden' name='id' value=''&gt;
                &lt;input type='hidden' name='username' value='".$_SESSION['user']."'&gt;
                &lt;input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'&gt;
                &lt;textarea name='message'&gt; &lt;/textarea&gt;
                &lt;br&gt;
                &lt;input style='' type='submit' name='commentSubmit' value='REAGEER'&gt;
                &lt;/form&gt;";
}else{
    echo " Log in om te reageren";
}
?&gt;

&lt;/div&gt;


    &lt;div class="reacties"&gt;&lt;br&gt;&lt;/div&gt;

&lt;?php   

 $sql = mysql_query("SELECT * FROM `comments`");
 while ($row = mysql_fetch_assoc($sql)){
        $id= $row['username'];
        $sql2 = mysql_query("SELECT * FROM `userlogin` WHERE `id` = '$id'");
        if ($row2 = mysql_fetch_assoc($sql2)){
                echo "&lt;div class='commentsDiv'&gt;";
                echo "&lt;img style='margin: 5px; left: -25px; width: 100px; height: 100px; border: 1px black solid;position: relative; display: inline;'src='".$row2['image']."'&gt;";
                echo '&lt;p style="color: #b73a09;font-size: 16px; font-weight: bold; top: 120px; left: 0px; display: inline; position: absolute;"&gt; '.$row2['uname'].'&lt;/p&gt;';
                echo '&lt;p style="color: #44444; font-size: 10px; left: 5px; top: -10px;  display: inline; position: absolute;"&gt; '.$row['date'].'&lt;/p&gt;';
                echo '&lt;p style="font-family: Poppins, sans-serif; color: #44444; text-align: justify;  padding-left: 150px; top: -125px; position: relative;"&gt; '.nl2br($row['message']);
            echo "";
            if(isset($_SESSION['user'])){
                if($_SESSION['user'] == $row2['id']){

                        echo "&lt;form class='commentDelete' method='POST' action='".deleteComments()."'&gt; 
                        &lt;input type='hidden' name='id' value='".$row['id']."'&gt;
                        &lt;button name='DeleteComment'&gt;Delete&lt;/button&gt;
                        &lt;/form&gt;
                        &lt;form class='commentEdit' method='POST' action='editComments.php'&gt; 
                            &lt;input type='hidden' name='id' value='".$row['id']."'&gt;
                            &lt;input type='hidden' name='username' value='".$row['username']."'&gt;
                            &lt;input type='hidden' name='date' value='".$row['date']."'&gt;
                            &lt;input type='hidden' name='message' value='".$row['message']."'&gt;
                        &lt;button&gt;Edit&lt;/button&gt;
                        &lt;/form&gt;";
            }else { 
                    echo "&lt;form class='commentEdit' method='POST' action='replycomment.php'&gt; 
                        &lt;input type='hidden' name='id' value='".$row['id']."'&gt;
                        &lt;button type=''&gt;Reply&lt;/button&gt;
                        &lt;/form&gt;";

                    }
            } else{
                echo "&lt;p class='commentMessage'&gt; Je moet inglogd zijn om te reageren! &lt;/p&gt;";
            }
                        echo "&lt;/div&gt;";
        }
 }



?&gt;  
</code></pre>