Post comment as logged in user
<p>I have a system where you can post a comment and it writes to a database, the user is required to write their name and comment.</p>

<p>What I'm trying to achieve is if a user is logged in, it will retrieve their username and post it as the name.</p>

<p>My log-in works perfectly fine</p>

<p>This is what I have so far</p>

<pre><code>$_SESSION['user_username']= $username;
</code></pre>

<p>This is the script that links to the form where users post a comment. I get a <code>line 7 error</code> when I try to post the comment.</p>

<pre><code>if (isset($_POST['comment_submit'])) {

$statement = $pdo-&gt;prepare('INSERT INTO comments (comment_username, comment_description, comment_art)
VALUES (:comment_user, :comment_desc, :comment_article)');

    $criteria = [
        'comment_user' =&gt; $_POST[$username],
        'comment_desc' =&gt; $_POST['comment_description'],
        'comment_article' =&gt; $_GET['article_id']
    ];

$stmt-&gt;execute($criteria);
}
</code></pre>

<p>Does anyone know why this does not work?</p>