1

I created a Inbox and Outbox system on my website where users can send and receive text messages.

I have created a tables in my DB

-Messagebox

MessageBox table contains the following 5 fields :

 messageID Message SentBy SentTo Created 

Inbox.php

 $you=$_COOKIE['username'];       $st= "SELECT* FROM Messagebox WHERE sentto='$you' ORDER BY ID DESC LIMIT 10";

outbox.php

  $you=$_COOKIE['username'];
$st= "SELECT*FROM messagebox WHERE sentby='$you' ORDER BY ID DESC LIMIT 10";

My problem is that When UserA sends a message to UserB ,UserA can see the message in Inbox and the Sender can see the sent message in his Outbox.

If The sender deletes the messege from Outbox ,Or UserA deletes the message from Inbox ,Then the messege is deleted from both sides.

How can I implement my system?

Any help would be greatly appriciated!

2
  • 3
    Add visibility flag in your table and only delete it when both have Commented Jun 24, 2015 at 6:13
  • 1
    Or store the message twice like E-Mail does. Once for the sender and once for the receiver. Commented Jun 24, 2015 at 6:41

1 Answer 1

2

You can add two flags for delete purpose. One flag is for deletedByReceiver and another is for deletedBySender. Set the appropriate flag whenever message deleted.

Another option is to maintain on more table which maintain the our and in of each message with message id. For more go through : Messaging system in php mysql

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.