The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Try out my first PHP web app! Reply To: Try out my first PHP web app!


Regarding this:

while ($row = mysqli_fetch_array($comments)) {

    $comment =  htmlentities($row['comment']); 
    $comment_by = $row['comment_by'];

    <div id='commentbox'>
    <p><?php echo $comment;?></p>
    <span class='detail1' id='username'><?php echo $comment_by;?></span>
    <button onclick='post()'>Click</button>


Why are you using an ID rather than a data-* attribute as discussed above? It would work fine, while using an ID would create multiple duplicate IDs on the page (which is invalid; every ID must be unique).

<div id="commentbox" data-username="<?php echo $comment_by ?>">
    <p><?php echo $comment;?></p>
    <button onclick="post()">Click</button>