Previous | Next

     We have the inbox done, and we can view messages if we have any, and we can select them for deletion and click a button to delete them, but this is the page that actually does the deleting stuff. It will recieve the information from the form as an array on which messages to delete, and will go through the process of deleting them. The messages will only be deleted if they are yours. This page will also subtract 1 from your total private message count for each private message deleted, then update it. There is no trash folder where they are sent, then deleted later, they just get deleted right away. Ohh yeah, after deleting you get sent back to your inbox, because otherwise you would be on a blank page that just says you deleted them.

$user $_SESSION['username'];
//We do not have a user check on this page, because it seems silly to, you just send data to this page then it directs you right back to inbox
    //We need to get the total number of private messages the user has
$sql mysql_query ("SELECT pm_count FROM users WHERE username='$user'");
$row mysql_fetch_array ($sql);
$pm_count $row['pm_count'];
//A foreach loop for each pm in the array, get the values and set it as $pm_id because they were the ones selected for deletion
foreach($_POST['pms'] as $num => $pm_id)
//Delete the PM from the database
mysql_query("DELETE FROM messages WHERE id='$pm_id' AND reciever='$user'");
//Subtract a private message from the counter! YAY!
$pm_count $pm_count '1';
//Now update the users message count with the new value
mysql_query("UPDATE users SET pm_count='$pm_count' WHERE username='$user'");

     One last thing real quick, if you encounter any problems during this tutorial or with code not working, PLEASE e-mail me at "bedfordd @" (Remove the spaces).

Part One - Getting Started: The first page will tell you how to set up the database and table that you will need for the Private Messaging System, and will also show you how to connect to the database you just created.

Part Two - Inbox: The second page will teach you first of all, how to make the inbox. This page will search for any message that have been sent to the logged in user, display them, let the user click a link to view them, and finally to select them for deletion.

Part Three - Delete: The third page will recieve the information from the inbox page for which private messages need to be deleted, process the information, and to actually do the deletion.

Part Four - View Messages: The fourth page will teach you how to recieve the id variable sent through the URL when you click the link on the inbox to view the message. It will double check that you are the reciever of the message, and will display the message in full.

Part Five - Compose: The fifth page will teach you how to make the form to write a message and to send the form to itself, do some error checking to make sure they didnt try to send a blank message, or a message to a non existant user, or a message to themself.

Part Six - Sent Messages: The sixth, and least useful page, will just show you which messages you have sent to other users that haven't been read or deleted yet.