MySQL
  Home arrow MySQL arrow Page 4 - 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 (contd.)


    (Page 4 of 6 )

    The GetInput function

    This function is responsible for generating the bottom frame of our chat window, and allows the user to enter their message in a text box and send it. If you look at the screen shot shown above, you will also see that the bottom frame contains a “Say” button (to submit the message), a color drop-down list (this lets the visitor choose the color of their message), and several icon-icon buttons.

    When we press enter in the text field, or click on the “Say” button, the JavaScript function “doSubmit” is called. This function will make sure that the visitor has actually entered a message. If they have, then the function will get the currently selected color from the drop-down list, and change the value of the text field so that it’s surrounded by <font> and </font> tags. The function will return true, and our form is submitted. If the text field is empty, the browser displays a message box kindly asking the user to enter a message and returns false, stopping the form from being submitted. The code for the “doSubmit” function is shown below:

    function doSubmit()

    {

    if(document.chatform.chat.value == '') {

    alert('Please enter some text!');

    document.chatform.chat.focus();

    return false;

    }

    document.chatform.chat.value = '<font color="'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';

    document.chatform.submit();

    document.chatform.chat.value = '';

    document.chatform.chat.focus();

    return true;

    }


    When one of the icon-icon buttons is pressed, the form will call the sendFace JavaScript function, which will automatically send either “:)”, “:(”, or “:D” to the top frame of our chat window. When the top frame receives either of these, the ShowAddPosts function will automatically display an image corresponding to that icon-icon, instead of the “:)”. So, for example, if we entered “:)” in the text field or clicked on the “:)” button, the top frame would display the appropriate icon-icon image, like this:

    Clicking on the smiley face icon-icon button

    The images for the icons-icons are included as part of the support material at the end of this article, and should be saved in the same directory as the chat.php script (which is also included as part of the support material).

    The code for the entire GetInput function is shown below:

    function GetInput() {

    global $HTTP_SESSION_VARS;

    global $chat;

    global $nick;

    ?>



    <form onSubmit="return doSubmit" name="chatform" method="post" action="chat.php" target="posts">

    <input type="text" name="chat">

    <input type="hidden" name="nick" value="<?php echo $nick; ?>">

    <input type="button" onClick="doSubmit()" name="Submit" value="Say">

    <select name="col">

    <option>Black</option>

    <option>Red</option>

    <option>Green</option>

    <option>Blue</option>

    <option>Orange</option>

    </select>



    <input type="button" name="DoFace1" value=" :) " onClick="sendFace(1)">

    <input type="button" name="DoFace2" value=" :( " onClick="sendFace(2)">

    <input type="button" name="DoFace3" value=" :D " onClick="sendFace(3)">

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

    </form>

    <script language="JavaScript">

    function sendFace(faceNum)

    {

    switch(faceNum)

    {

    case 1:

    document.chatform.chat.value = ':)';

    break;

    case 2:

    document.chatform.chat.value = ':(';

    break;

    case 3:

    document.chatform.chat.value = ':D';

    break;

    }



    document.chatform.submit();

    document.chatform.chat.value = '';

    }

    function doSubmit()

    {

    if(document.chatform.chat.value == '') {

    alert('Please enter some text!');

    document.chatform.chat.focus();

    return false;

    }

    document.chatform.chat.value = '<font color="'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';

    document.chatform.submit();

    document.chatform.chat.value = '';

    document.chatform.chat.focus();

    return true;

    }

    </script>

    <?php

    }


    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 5 hosted by Hostway
    Stay green...Green IT