Mini-Chat Tutorial
(Page 1 of 4 )
This tutorial is about my mini-chat script. It's not really a chat, since dialogs are updated only when page refreshes. It is the first tutorial of a series for some development techniques. Right now, I will focus on explaining how I managed the building of this mini-chat.
By : greggory
First thing to ask is what is chatting? So what do I need to Code? Basicly, a chat is a set of messages posted by someone, and in the order they've been posted. So we can write a first form, having two fields 'login' and 'message'. Then, we have to append it to a file, or better, a database. The details for the form syntax may be found in Matt's Tutorial.
<html> <head> <title>Mini Chat Sample</title> </head> <body> <form method="post"><br> Login:<input type="text" name="login" size="6"><br> Message:<input type="text" name="message" size="10"><br> <input type="submit" value="Send"><br> </form> </body> </html> |
We also need, of course, the DB schema and a function to insert to message.
<?php /* CREATE TABLE MINICHAT ( LOGIN varchar(20) NOT NULL default '', MESSAGE varchar(255) NOT NULL default '', ITSTIME varchar(10) NOT NULL default '' ); */
// Add message into minichat function addMessage( $login, $message ) {
$login = mysql_escape_string( strip_tags( $login ) ); $message = mysql_escape_string( strip_tags( $message, '<a><b><i><u>') ); mysql_query( "INSERT INTO MINICHAT ( ITSTIME, LOGIN, MESSAGE ) VALUES ( "'".time()."', '".$login."','".$message."' )"); }
// Message Posted ? if ( isset( $_POST['msg'] )) { addMessage( $_POST['login'], $_POST['msg'] ); } ?> |
Next: Basic Printing >>
More Miscellaneous Articles
More By Codewalkers