Hi All.
This is an HTML/PHP issue I've been tearing my hair out over and I thought maybe someone might be able to give me some advice.
I've written a simple guest book-type message board. I want to give users the ability to delete or "mask" messages so that they don't contine to see them. In order to do this, I've embedded a "Submit" button that posts the Users's ID and the Message_ID back to the form. I then use an ISSET to flip the "masked" flag to that particular message.
Now the problem is that I display the messages as part of a loop. So, the SUBMIT button is posting the last message_ID displayed rather than the ID of the message the user chooses to delete. It's actually even a little inconsistant at that.
Here is the basic flow:
1) Look up Messages waiting for the User
2) While there are still messages;
-- If the message is masked, don't display
-- If not masked, then display
-- Display a "Delete" Button
-- If Button is clicked, pass the message_ID for use by an ISSET function
3) Next Message
Unfortunately, even though the correct message_id is displayed at the point a create the "HIDDEN" variable for POSTING (passing) back the form, I think it's still passing the last message_id displayed rather than the correct one.
Maybe this isn't the way I should be going about this...I don't know. Basically, if you look at PHPADMIN, and you browse a table, you can see a "Delete" link on each row...this lets you delete the row. I'm looking to do something similar (set a flag to "Y" if clicked)... Still, I imagine the button or link should be do-able.
Any advice would be appreciated. For anyone interested by this problem, here is an actual code snippet:
/******************************/
/* Get linked user's messages */
/******************************/
while ($row = mysql_fetch_array($result2))
{
$original = $row["message_id"];
$message = $row["message"];
$date = $row["date"];
/*********************/
/* Check for Masking */
/*********************/
$sql_mask = "select * from users_mask where (user_id = '$user_id' and message_id = '$original')";
$result_mask = mysql_query($sql_mask);
$num_masked = mysql_num_rows($result_mask);
if ($num_masked == 0) {
/***************************/
/* Get Poster's Login Name */
/***************************/
$sql3 = "select * from users where user_id = $select[user]";
$result3 = mysql_query($sql3);
$row2 = mysql_fetch_array($result3);
$dbuser = $row2["user_login"];
?>
<br>
<form action="main_pb.php" method="post">
<table align="center" width="95%">
<tr>
<td class="main">
<b>Posted By: </b><? echo $dbuser; ?><br>
<b>Posted On: </b><? echo $date; ?><br>
</td>
<td align="right" valign="top">
// Note: Here the "$original" value is the correct one (i.e., the current message's ID)
// Yet, when the SUBMIT is clicked, it passes the wrong ID (i.e., usually the last one in the loop)
<input type="hidden" name="SID" value=<? echo $SID; ?>>
<input type="hidden" name="message_id" value=<? echo $original; ?>>
<input style='font-size: 9; font-face: verdana,ariel,helvetica; font-color='#000033' type="submit" value="Delete" name="delete">
</td>
</tr>
<tr>
<td class="main" colspan="2">
<br>
<? echo $message;?>
<br>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<br>
<hr>
</td>
</tr>
</table>
<?
}
}
}
?>