hi my name is lester page and i have a problem that is displaying links to the owner of the comment. the code is working fine but the thing is the links are being displayesd whether the logged in user is the owner or not. the database i have heading and comment with the user name and the author the author is the same as the username. please help below is the code

<?php
include('includes/setting.php');
$for=mysql_query('SELECT * FROM commentsss');

while($fores=mysql_fetch_array($for)){
echo "<table width='85%' border='1' align='center'>
  <tr>
    <td width='126' rowspan='2'><p><strong><br><br><br><br>Username</strong>: ".$fores['username']."</p><strong><br>Email:</strong> <p>".$fores['email']."</p></td>
    <td height='121' colspan='2'><h2>Title: ".$fores['heading']."</h2></td>
    <td width='126' rowspan='2'><h4><br><br><br><br><br><a href=\"editscommsss.php?post_id=
    ".$fores['post_id']."&heading=".$fores['heading']."\">Edit</a> | <a href=\"deletecommsss.php?post_id=
    ".$fores['post_id']."&heading=".$fores['heading']."\">Delete</a></h4></td>
    </tr>
  <tr>
    <td height='136' colspan='2'><strong>Comment:</strong><p>".$fores['comment']."</p></td>
    </tr>
  </table>";
}
?>

thank you in advance

Where is the information about the logged-in user stored? Let's assume that is stored in the session in the $_SESSION['loggedin_username'] variable. Now while fetching rows you have to check whether the fetched username equals to the logged-in username. So the code would be something like:

<?php
include('includes/setting.php');
$for=mysql_query('SELECT * FROM commentsss');
while($fores=mysql_fetch_array($for)){
echo "<table width='85%' border='1' align='center'>
  <tr>
    <td width='126' rowspan='2'><p><strong><br><br><br><br>Username</strong>: ".$fores['username']."</p><strong><br>Email:</strong> <p>".$fores['email']."</p></td>
    <td height='121' colspan='2'><h2>Title: ".$fores['heading']."</h2></td>
    <td width='126' rowspan='2'>";
    // Here you check the username from the database with the logged-in username
    // and disply the links if they match
    if($fores['username'] == $_SESSION['loggedin_username']) {
        echo "<h4><br><br><br><br><br><a href=\"editscommsss.php?post_id=".$fores['post_id']."&heading=".$fores['heading']."\">Edit</a> | <a href=\"deletecommsss.php?post_id=
        ".$fores['post_id']."&heading=".$fores['heading']."\">Delete</a></h4>";
    }
    echo "</td></tr>
  <tr>
    <td height='136' colspan='2'><strong>Comment:</strong><p>".$fores['comment']."</p></td>
    </tr>
  </table>";
}
?>

I didn't test this piece of code since obviously I do not have enough data. But you get the concept.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.