Dom Mv
11-18-2011, 12:29 AM
I have recently started to learn PHP and have come across a small problem that I can't resolve. I have created a page for sending a message (submitting data to the database) and a page for viewing (retrieving data from the database) the messages. What I would now like to do is create a delete button that removes individual messages from the database.
Here is what I have got so far:
//Connects to database:
<?php
include ('./connect.php');
?>
<?php
$db;
$messageInbox = mysql_query("SELECT * FROM messages");
while($inbox = mysql_fetch_array($messageInbox))
{
echo "
<hr>
<form action='./messageinbox.php' method='post'>
<table>
<tr>
<td>ID:</td>
<td>" . $inbox['id'] . "</td>
</tr>
<tr>
<td>Name:</td>
<td>" . $inbox['name'] . "</td>
</tr>
<tr>
<td>Subject:</td>
<td>" . $inbox['subject'] . "</td>
</tr>
<tr>
<td>Message:</td>
<td>" . $inbox['message'] . "></td>
</tr>
<tr>
<td colspan='2'><input type='submit' name='delete' value='Delete Message'></td>
</tr>
</table>
</form>
";
}
if(isset($_POST['delete']))
{
mysql_query("DELETE FROM messages");
}
mysql_close($con);
?>
I am able to deletes all entries, but not individual ones. I understand that the solution revolves around using the id, but I haven't managed to accomplish my goal as of yet.
Any help would be greatly appreciated. :)
Here is what I have got so far:
//Connects to database:
<?php
include ('./connect.php');
?>
<?php
$db;
$messageInbox = mysql_query("SELECT * FROM messages");
while($inbox = mysql_fetch_array($messageInbox))
{
echo "
<hr>
<form action='./messageinbox.php' method='post'>
<table>
<tr>
<td>ID:</td>
<td>" . $inbox['id'] . "</td>
</tr>
<tr>
<td>Name:</td>
<td>" . $inbox['name'] . "</td>
</tr>
<tr>
<td>Subject:</td>
<td>" . $inbox['subject'] . "</td>
</tr>
<tr>
<td>Message:</td>
<td>" . $inbox['message'] . "></td>
</tr>
<tr>
<td colspan='2'><input type='submit' name='delete' value='Delete Message'></td>
</tr>
</table>
</form>
";
}
if(isset($_POST['delete']))
{
mysql_query("DELETE FROM messages");
}
mysql_close($con);
?>
I am able to deletes all entries, but not individual ones. I understand that the solution revolves around using the id, but I haven't managed to accomplish my goal as of yet.
Any help would be greatly appreciated. :)