I'm creating a commenting system for signed in users. It is very simple, I just want the user's username and the comment posted on the page and then stored in my user_comments table.
I have two db tables I am working with users and user_comments. All of the username info is stored in my users table. I want the comments to be stored into the user_comments section and post from there. Then I want the user's username to be echod next to the comment and then stored in with the user_comments after submitted. I can't figure out how to sync all of this together. As of now this posts and the comment stores into my user_comments.
How would I get the user's username to post and then be stored into the user_comments table?
<form action="communitySignedIn.php" method="POST">
    <label for="comment">Comment</label>
    <textarea cols="15" name="comment" placeholder="Message" class="messageinput" rows="5" maxlength="1000" required></textarea><br>
    <input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
    <input id="signinButton" name="submit" type="submit" value="Comment">
</form><br><br>
<?php
    if(isset($_POST['submit'])){ 
        $comment = trim( $_POST['comment'] );; 
        $okay = true;    
        if( strlen($comment) < 2 ) { 
            echo "Please enter another character<br>"; 
            $okay = false; 
        } 
        // you would do other validation here if other fields 
        if ( $okay ) { 
            $con = mysqli_connect("localhost", "root", "", "bfb"); 
            $q = mysqli_query($con,"INSERT INTO user_comments (id, comment) VALUES ('', '$comment')") 
                or die("Could not INSERT: " . mysql_error()); 
            echo "Your comment was successfully posted.<br/ ><br /><br /><br />"; 
        } 
    }
?>
<?php
    $con = mysqli_connect("localhost", "root", "", "bfb");
    $run = mysqli_query($con,"SELECT * FROM user_comments ORDER BY id DESC");
    $numrows = mysqli_num_rows($run);
    if($numrows > 0){
        while($row = mysqli_fetch_assoc($run)){
            $dbname = $row['name'];
            $dbcomment = $row['comment'];
            echo 'escape($user->data()->username)';
            echo "Comment: $dbcomment<br><br><hr>";
        }
    }
    else
        echo "No Comments Found...";
?>
