The error message you are encountering is indicating that the variable
$posted_by is undefined in your code. This occurs on line 39 of your code, in the file
comment.php.
To fix this issue, you need to ensure that the variable
$posted_by is defined before attempting to use it on line 39. Looking at your code, you are fetching data from the database using a
SELECT statement and storing the results in the
$post_row variable within a while loop. However, you are only assigning values to the
$posted_by variable within the loop, which means it will only be accessible within the loop.
To resolve this, you can move the line that echoes the
$posted_by variable inside the loop, so that it is executed for each iteration of the loop. Here's an updated version of your code that should fix the issue:
PHP:
<?php
$slq = mysqli_query($con, "SELECT * FROM post LEFT JOIN registration on registration.user_id = post.user_id ORDER BY comment_id DESC " ) or die (mysqli_error());
while($post_row = mysqli_fetch_array($slq)){
$id = $post_row['comment_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['username'];
// Move the echo statement here, inside the loop
echo '<a style="text-decoration:none; float:right;" href="#"><button><font color="red">x</button></font></a>';
echo '<h3>Posted by: <a href="#">' . $posted_by . '</a></h3>';
}
?>
By making this change, the
$posted_by variable will be defined and accessible within the loop, so you can safely echo its value without encountering any undefined variable errors.