Chat itself:

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

And this is an iframe:

 <script type="text/javascript"> setTimeout("window.location.reload()",15000); // Обновление раз в 15 секунд </script> 

and

 <?php session_start(); if (isset($_POST['message'])) { $message = $_POST['message']; } $db = mysql_connect("...", "...", "..."); mysql_select_db("...", $db); if (trim($message) != "") { mysql_query("INSERT INTO messages (message,username) VALUES ('$message','{$_SESSION['username']}')"); } $result = mysql_query("SELECT * FROM messages"); while ($row = mysql_fetch_array($result)) { echo "<br>"; echo "{$row['message']}"; echo $row['username']; } ?> 

And the chat script:

 <script> jQuery(function ($) { $("#form").onsubmit(function (event) { var message = $("input[name='message']", form).value() if (message) { event.preventDefault(); return false; } return true; }); $("#form input[name='message']").bind('change keydown keypress', function (event){ var text = $(this).value().replace(/^\s+/, "").replace(/\s+$/, ""); $("#form input[type='submit']").prop("disabled", text == ""); }); }); </script> 

    1 answer 1

     while ($row = mysql_fetch_array($result)) { echo "<br>"; echo "{$row['message']}"; echo "&nbsp;".$row['username']; //&nbsp; - неразрывный пробел. } 

    This is the simplest option.
    PS You are not familiar with Vlad?