Hello All,
Below i my code which enables a user to see all the comments in his profile when logged in. It also has a code which becomes visible to a user’s friend when he visits his profile. Now i want to display an option of delete in front of each comment. When the orginal profile holder or the one who posted it visit the comments section,delete button should appear and in rest case it should not. The only comment needs to be deleted whose delete button is pressed. How should i do it?
<?php
$sql="SELECT * FROM comments WHERE for_msg='$u'";
$query=mysqli_query($db_conx,$sql);
$numrows = mysqli_num_rows($query);
if($numrows>0)
{$show=" You have $numrows Comments";}
else{$show="You dont have any comments yet.";}
if($u != $log_username && $user_ok == true){
$comment_form = '<form id="usercommnet" method="post">';
$comment_form .= '<h4>Post Your comment for </h4>';
$comment_form .= '<input type="text" name="coment" required>';
$comment_form .= '<p><input type="submit" value="Submit" name="comet"></p>';
$comment_form .= '</form>';
}
else $comment_form="";
?>
<?php
if(isset($_POST['comet'])&& $_POST['coment']!="")
{
$remov=$_POST['coment'];
$sql="INSERT INTO comments (comment,from_msg,for_msg,datecreated) VALUES('$remov','$u','$log_username',now())";
$query=mysqli_query($db_conx,$sql);
if($query===TRUE){echo " yahoo";}
exit();
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
.showcomments{width:70%; height:auto; border:#099 1px solid; margin-top:5px; margin-bottom:1px;}
</style>
</head>
<body>
<div><?php echo $show;?></div>
<?php
$sql="SELECT * FROM comments WHERE for_msg='$u' ";
$query=mysqli_query($db_conx,$sql);
$numrows = mysqli_num_rows($query);
if($numrows < 1){
$filename= "You dont have any comments";
exit();
}
else
$i=1;
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$from_msg = $row["from_msg"];
$for_msg = $row["for_msg"];
$comment = $row["comment"];
$datecreated = $row["datecreated"];
$code = $row["code"];
$id = $row["id"];
$filename="$i $from_msg $comment ";
$i=$i+1;
?>
<div class="showcomments">
<?php echo $filename;?><br></div>
<?php
}// Close Main while loop
?>
<?php echo $comment_form;?>
</body>
</html>