Ive been working on my delete.php file to delete selected messages for literally hours on end without any headway. How would I delete messages with the codes I have set up?
Heres the code to how my delete.php is set up right now
<?php
session_start();
header("Location:inbox.php");
$user = $_SESSION['username'];
include 'connect.php';
foreach($_POST['messages'] as $num => $messages_id)
mysql_query("DELETE FROM messages WHERE messages_id='$messages_id' AND to_user='$user'");
?>
Here’s the code to my entire inbox.php
<?php
require "connect.php";
echo "<hr><br><div id='mail'>";
// get the messages from the table.
$get_messages = mysql_query("SELECT messages_id FROM messages WHERE
to_user='$userfinal' ORDER BY messages_id DESC") or die(mysql_error());
$get_messages2 = mysql_query("SELECT * FROM messages WHERE to_user='$userfinal'
ORDER BY messages_id DESC") or die(mysql_error());
$num_messages = mysql_num_rows($get_messages);
// display each message title, with a link to their content
echo '<ul>';
for($count = 1; $count <= $num_messages; $count++)
{
$row = mysql_fetch_array($get_messages2);
$fromuser = $row['from_user'];
$messageid = $row['messages_id'];
$messagetitle = $row['message_title'];
$messageread = $row['message_read'];
$messagedate = $row['message_date'];
echo " <form name='send' method='post' action='delete.php'><input type='checkbox' name='delete' value='$messageid'></td><font face='helvetica'><font size='3'>$fromuser</font></font> • <div align='right'><a href='read_message.php?messages_id=$messageid'>$messagetitle</a></div>
<center><hr></center>
";
}
?>
<input type="submit" name="Submit" value="Delete Selected">
</table>
</div>
Please help out before my head explodes
You are using
header("Location:inbox.php");in the second line of your code, so the rest of it never gets executed.Just move it to the end of the script, after you have deleted the messages you wanted to delete.