views:

34

answers:

1

Hello, I am still a newbie.So that being said, my site has a messaging system that allows users to delete their sent messages. Its been discovered that if I erase my messages out of my 'sent' box, it erases the message out of the recipients inbox. I have two ways to delete messages out of your sent mail, 'erase all messages' and one by one.

Here is my code for the erase all:

function deleteAll() {
    var answer = confirm('Are you sure you want to delete all of your messages?');
    if(answer){
        return true;
    }else{
        return false;
    }
}

if(isset($_POST['subEraseAll'])){

    $query = "UPDATE `Messages` SET `status` = 'dead' WHERE `sentFrom` = '".$auth->id."'";
    mysql_query($query,$connection) or die(mysql_error());

    <div class="EraseAll">
                                    <form name="EraseAll" action="SentMail.php" method="post" onsubmit="return deleteAll();">
                                    <input  type="submit" name="subEraseAll" value="Erase All Messages" />
                                    </form>
                                    </div>

Here is the code to delete messages one by one via the deleteConfirmPage:

 $message = $_GET['id'];

    $query = "SELECT * FROM `Messages` WHERE `id` = '" . $message . "'";
    $request = mysql_query($query,$connection);
    $result = mysql_fetch_array($request);

    $toUser = $result['sentTo'];
    $fromUser = $result['sentFrom'];

    if($auth->id !=$fromUser) {
        header("Location: index.php");
        exit;
    }

    $query = "UPDATE `Messages` SET `status` = 'dead' WHERE `id` = '".$message."' LIMIT 1";
    $request = mysql_query($query,$connection);

So my question is how do I stop my query from erasing sent messages from my sent box out of the recipients inbox
Thank you!

+2  A: 

To do this you may need to change the structure of your table some, or change how you use the 'status' column.

Here is a potential solution which proposes a change to the table structure, but I can't be sure if it will work (or even be relevant) without more information:


Right now your message table only has a 'Status' column, what it really needs is a 'Status Sender' column and additionally a 'Status Receiver' column.

When the sender deletes the message set the 'Status Sender' value to 'dead', and when the receiver deletes the message set the 'Status Receiver' to 'dead'

This means when you are displaying messages in a users inbox that you need to query for 'Status Reciever' = 'alive', and when you are displaying messages in a users sent folder, you need to query for 'Status Sender' = 'alive'.


Note: This design doesn't bode well for scenarios where a single user sends a message to multiple recipients.

instanceofTom
makes alot of sense. I knew it was something to that nature but was not sure what. Thank you!
Ralph The Mouf
No problem :-).
instanceofTom