MySQL
  Home arrow MySQL arrow Page 3 - A MySQL Driven Chat Script
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

A MySQL Driven Chat Script
By: Tim Pabst
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 200
    2001-12-25

    Table of Contents:
  • A MySQL Driven Chat Script
  • Creating the database
  • The chat script explained
  • The chat script explained (contd.)
  • The chat script explained (contd.)
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    A MySQL Driven Chat Script - The chat script explained


    (Page 3 of 6 )

    Our chat script will be created as only one file, named “chat.php”. It will contain four functions named ShowLoginForm, Login, GetInput and ShowAddPosts. These four functions are described below.

    The ShowLoginForm function

    The ShowLoginForm function is called whenever a visitor loads our chat.php script for the first time. It will display a HTML form that contains a field for the user to enter their nickname into. Once this form is submitted, the Login function is called.

    The code for the ShowLogin function looks like this:

    function ShowLoginForm() {

    ?>

    <b>Enter Your NickName</b>

    <form name="chat" method="post" action="chat.php" target="_top">

    <input type="text" name="nick" size="20">

    <input type="hidden" name="action" value="enter">

    <input type="hidden" name="chat" value="<font color=FF0000><b>Enters the Room</b></font>">

    <input type="submit" name="Submit" value="Submit">

    </form>

    <?php

    }


    The output from the ShowLogin function looks like this:

    Output from the ShowLoginForm function

    The Login function

    The login function is responsible for taking the users nickname (which is passed to the function from the login form created by the ShowLoginForm function) and creating a new session variable from it. This session variable will allow our chat script to track the user throughout their entire chat session, until they close their browser window. The login function also displays the actual frames for the chat page, by using one <frameset> HTML tag and two <FRAME> tags. The code for the Login function is shown below:

    function Login() {

    global $chat;

    global $nick;



    session_start();

    session_register("nick", $nick);

    ?>

    <frameset rows="563,62" cols="*">

    <frame name="posts" src="chat.php?action=posts&nick=<?php echo $nick; ?>&chat=<?php echo $chat; ?>">

    <frame name="form" src="chat.php?action=form&nick=<?php echo $nick; ?>">

    </frameset>

    <noframes>

    <body>

    <p>This page uses frames, but your browser doesn't support them.</p>

    </body>

    </noframes>

    </frameset>

    <?php

    }


    The <frameset> tag creates two horizontal frames: The first (the main chat window, which will display the messages) is 563 pixels high. The second (which will allow the visitor to enter their message) is 62 pixels high. Pay careful attention to the “src” attribute of the two <frame> tags. You will notice that they pass an “action” value, as well as the users nickname as part of the URL’s query string. We will talk more about this in just a minute.

    The output from the Login function looks like this:

    The output from the Login function

    Remember how we added a test record to the “chatscript” table when we were creating it? If you take a look at the screen shot above, you can see that it appears in the contents of our main chat window. The actual contents of the top and bottom frames shown above are generated by the GetInput and ShowAddPosts functions. They are described below.

    More MySQL Articles
    More By Tim Pabst


       · not work
       · The code does not work at all in its present form.A number of bugs are there. For...
       · this is i have coppied and tested . but it is not working right. pls check and reply...
       · The code is absolutely rubbish. It does not work. A dirty joke by the writter
       · We're sorry the code doesn't work for you. I think you will find that our more...
     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT