How to display a message in the chat window?

I have a chat and an iframe. The message is entered into the database, but how to display it through the loop does not work.

Here is the chat:

<iframe name='chatWindow' id='chatWindow' src ="iframe.php" width="1265" height="400"></iframe>   
<form action="iframe.php" method="post" name="form" target='chatWindow' >
<p>:<input name="message" type="text" size="75" maxleght="255">
<input name="submit" type="submit" value="OK">

And iframe:

if (isset($_POST['message']))
$message = $_POST ['message'];
$db = mysql_connect("","**","**");
$result = mysql_query("INSERT INTO messages (message) VALUES ('$message')");

Answer 1, authority 100%

As far as I can tell, your chat is done with constant reloading of the iframe. If so, then after you enter the message into the database, you just need to select the last ones from it, how many you need or all (it’s up to you) and display them on the user’s screen.
If your iframe is not a field where messages are written, then you need to make more calls to the script that will check how much is on your screen (which is the last one – it is better to use a variable in the session containing the last ID) and watch , how many after it there are still in the database and send them to the user. Of course, everything is done through Ajax.