How to make chat in PHP + MySQL?

Hello experts. How to make a chat in PHP + MySQL on the site. Thank you in advance. )


Answer 1, authority 100%

iframe.php::

<script type="text/javascript">
setTimeout("window.location.reload()",5000);//   5 
</script>
<body>
<?php
if(isset($_POST['message'])){
  $sql = "insert into `messages` (`message`) values ('".$_POST['message']."')";
  mysql_query($sql);
}
$sql = "select `message` from `messages` where 1 order by id desc";
$res = mysql_query($sql);
while($row = mysql_fetch_object($res)){
 printf("<div>%s</div>",$row->message);
}
?>
</body>


chat.php::

<body>
<iframe name='chatWindow' id='chatWindow' src='iframe.php'></iframe>
<form action='iframe.php' method='post' target='chatWindow'>
<input type='text' name='message'>
<input type='submit' />
</form> 
</body>

The easiest chat. You can upgrade to infinity, the principle is stated.
P.S. The editor is buggy again. Someone promised that I would soon be imbued with his convenience. Is it that hard to install CKEdit or something like that?