I have a comment system that loads the db, checks the profile page your on, then checks the database for the same username. If they match it echos the comment. This is all done in a while loop. Im trying to now create a ‘Remove Comment’ feature but im having some issues. Im guessing because its a while loop it doesnt know what one you are talking about. Ive tried making the submit button have same ID as the comment so they correspond and it knows what to remove but that doesnt work.
Ive added an echo to see if when i click Remove comment if it does anything and nothing does.
Here is my code:
[code] <?php
$connect = mysql_connect("localhost","airsoftg_admin","pimpon316") or die("couldnt connect!");
mysql_select_db("airsoftg_news") or die("Couldnt find DB!");
$result=mysql_query("SELECT * FROM comments");
$num=mysql_numrows($result);
mysql_close($connect);
$min = $num - 10;
$i = $num - 1;
echo "<form action='profile.php?username=<?=$pdbusername?>' method='POST'>";
while ($num > $min && $num > 0)
{
$comment = mysql_result($result,$i,"comment");
$commentuser = mysql_result($result,$i,"commentuser");
$commentdate = mysql_result($result,$i,"commentdate");
$commentto = mysql_result($result,$i,"commentto");
$commentid = mysql_result($result,$i,"commentid");
if(strtolower($pdbusername)==strtolower($commentto))
{
echo "<div>";
echo "<div class='fl imgborder' style='padding:10px;'>";
$connect = mysql_connect("localhost","airsoftg_admin","pimpon316") or die("couldnt connect!");
mysql_select_db("airsoftg_login") or die("Couldnt find DB!");
$query = mysql_query("SELECT * FROM users WHERE username='$commentuser'");
$numrows = mysql_num_rows($query);
mysql_close($connect);
if ($numrows!=0)
{
echo "<div class='fr' style='padding:10px;'>
<div class='news02'>
<input type='submit' name='remove$commentid' value='Remove Comment' class='removecomment'/>
</div>
</div>";
}
}
$num--;
$i--;
}
echo "</form>";
$remove = $_POST['remove$commentid'];
if($remove)
{
mysql_query("DELETE FROM comments WHERE commentid='$commentid'");
}
?>[/code]
Probably doesn’t make much sense but its the best i can explain it. If anyone wants to Team Viewer, ill be willing to do that.