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 if (isset($_POST['message'])) { $message = $_POST['message']; } $db = mysql_connect("...", "...", "..."); mysql_select_db("...", $db); if (trim($message) != "") { mysql_query("INSERT INTO messages (message) VALUES ('$message')"); } $result = mysql_query("SELECT * FROM messages"); while ($row = mysql_fetch_array($result)) { echo "<br>"; echo "{$row['message']}"; } ?> 

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> 

    2 answers 2

    Pre-authorize and write the nickname to the session with something like:

     $_SESSION['username']='Вася'; 

    Next, fix php:

     <?php session_start();//подключаем сессию самая первая строчка в пхп скрипте if (isset($_POST['message'])) { $message = $_POST['message']; } $db = mysql_connect("...", "...", "..."); mysql_select_db("...", $db); if (trim($message) != "") { //соответвенно не забываем добавить в таблицу поле username 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'];//выводим имя } ?> 
       CREATE TABLE `chat` ( `id` параметры `user` параметры `massage` параметры `time` параметры ); 

      And accordingly a script of record and reading.

       в итоге $row['time'] $row['user'] $row['message'] 

      From the correct construction of the tables in the database, you get the correct further work and execution of the script without a dozen completions and rework !!!