hoping you can help with what I expected to be a simple function.
I’d like to allow users to remove (i.e. change published=y to published=n) a query result but can’t for the life of me figure out how to do it. Here’s the query as is:
$result = mysql_query("SELECT * FROM discussion WHERE publish='y' ORDER BY timestamp DESC");
while($row = mysql_fetch_array($result))
{
echo ("<tr><td>" . $row['name'] . "<span class=\"remove\">(<a href=\"#\">REMOVE</a>)</span></td>
<td width=\"300\">" . nl2br($row['question']) . "</td>
<td>" . $row['author'] . "</td>
<td>" . $row['timestamp'] . "</td>
<td><a href=\"discussion.php?discussionID=" . $row['discussionID'] . "\">View Discussion</a></td></tr>");
}
The query I’d like to run when the user clicked ‘REMOVE’ (within the above query):
mysql_query("UPDATE discussion SET publish='n' WHERE discussionID='XXXXX");
Any ideas from the fine people at SO?
New to php/mysql so forgive the ignorance.
I think the simplest option here would be to insert your remove button into a form.
Try adding this form into your table. I am echoing the discussionID into the checkbox so that you can distinguish between the multiple checkboxes in the table:
And then in your PHP, you update the database with the value of the checkbox:
Does that make sense?
EDIT: This should now work! Also updated to include Dan’s suggestion.