Your code doesn't offer much of an explanation about how it is intended to work, so I'm going to have to take a forensic approach to the debugging.
The problem you find is that you get output like this:
you told wilku hi
you told wilku how are you doing today
you get:
Dragonlord told you hi
you told wilku how are you doing today
In the above example, the last line is fine, but the previous line(s) do something bad with the names of the sender and recipient.
The sender's message history is somehow getting screwed. You tell us that the sender is $user.
Somehow $theperson's history is appearing where $user's should be.
You don't mention that $theperson's history is getting screwed up, so I won't follow that up.
In order to load up $user's message history, you do this:
mysql_query("SELECT * FROM `character` WHERE Who='y' AND User='$user'");
while ($row = @mysql_fetch_array($queryb))
{
$messages=$row["messages"];
}
Take a closer look at this. You build up a query to extract $user's message history, you fire that query off to mysql, but you may as well not have - you're not doing anything with the returned value. It just disappears.
What you do use is the value returned from $queryb. But what is $queryb? Look further up in the code...
$queryb = mysql_query("SELECT * FROM `character` WHERE Who='y' AND User='$the_person'");
This is why $the_person's history ends up overwriting $user's.