Web Design and Web Development Forum

  1. #1
    Join Date
    Sep 2004
    Location
    On here of course
    Posts
    141
    Rep Power
    9
  2. Vio-Bear is on a distinguished road Vio-Bear is on a distinguished road
  3. Php Shoutbox Tutorial

    Source: http://www.media-ops.com

    My first ever tutorial! (php wise...). I first made this for www.re-mi.be, which is currently down, and then updated it and now i use it on my personal site www.r.dsx3.com :P. Its a basic script, but if you would like a shout box then it is perfect :P.

    There will be 5 parts to this tutorial:
    >Making the SQL Table
    >Creating the Form
    >Creating the Action
    >Creating the Output
    >Creating the index

    lets get started :P.

    Open up Phpmyadmin, or whatever you use for sql. Run this query
    Code:
    CREATE TABLE `shout` (
    `id` INT NOT NULL AUTO_INCREMENT ,
    `name` TEXT NOT NULL ,
    `message` TEXT( 100 )  NOT NULL ,
    PRIMARY KEY ( `id` )
    );
    You can change the 100 (in the paranthesis) to however many characters you would like to limit the peoples messages to.

    What the query does, for people who dont get it: It creates a table called shout, and makes three rows. ID, name, and message. The name and message are inputted by the user, and the id automaticaly increases each time a person "shouts".

    now create a directory called shout. You dont want things to get all ugly and disorganized :P.

    Now we are going to create the form. Name this add.php
    Code:
    <form name="addform" method="post" action="shoutbox/action.php">
    <table width="150" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><b>Name:</b></td>
        <td><input type="text" id="name" name="name"></td>
      </tr>
      <tr>
        <td><b>Msg:</b></td>
        <td><input type="text" id="message" name="message"></td>
      </tr>
    </table>
    <table width="150" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="center"><input type="submit" name="shout" title="shout" value="shout"></td>
      </tr>
    </table>
    </form>
    I put it in the table so i could control the alignment :P. You could/should add some css, to make the inputs look pretty :P, because the default ones arent so.

    Now we are going to make the action file. Name this action.php <-- :P

    Code:
    <?php
    
    //fill it out according to the sql table you set up
    $username="Username";
    $password="Password";
    $database="Database";
    $table="shout";
    
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $query="INSERT INTO $table (id, name, message) values ('$id','$name','$message')";
    $result=mysql_query($query);
    echo "Succsesfully Shouted. <a href=\"http://www.yoursite.com\">Return</a>";
    ?>
    Make sure, when you change the href, to keep the last \ there :P. Change the username pswrd and databae names also.
    Reply With Quote Reply With Quote
  4. #2
    Join Date
    Apr 2007
    Posts
    5
    Rep Power
    0
  5. Lukeoxley is on a distinguished road
  6. Re: Php Shoutbox Tutorial

    what is a good url to use to lern php
    Reply With Quote Reply With Quote
  7. #3
    Join Date
    Mar 2005
    Location
    London, UK
    Age
    21
    Posts
    145
    Rep Power
    8
  8. johnnie is on a distinguished road
  9. Re: Php Shoutbox Tutorial

    Well, after a quick Google on Learning PHP, I found this:
    http://www.communitymx.com/content/a....cfm?cid=D5084

    which seems useful, also you can try http://php.net

    However, this thread was submitted in 2005, so don't expect a reply from the original poster.

    And I believe a Moderator / Staff Member will probably tell you to start a new thread, rather than replying to very old threads
    Reply With Quote Reply With Quote
  10. #4
    Mitch's Avatar
    Join Date
    Dec 2004
    Location
    United Kingdom
    Age
    23
    Posts
    2,481
    Rep Power
    0
  11. Mitch will become famous soon enough Mitch will become famous soon enough
  12. Re: Php Shoutbox Tutorial

    Start a new thread ;).
    Reply With Quote Reply With Quote
  13. #5
    cancer10's Avatar
    Join Date
    Jun 2005
    Location
    India
    Age
    29
    Posts
    498
    Rep Power
    7
  14. cancer10 is on a distinguished road
  15. Re: Php Shoutbox Tutorial

    Just for your information people,

    This shoutbox wont work since it does not have an auto refresh which would populate the new messages to other visitors.
    Reply With Quote Reply With Quote
  16. #6
    Join Date
    Sep 2005
    Location
    UK
    Age
    27
    Posts
    807
    Rep Power
    0
  17. bfsog is on a distinguished road
  18. Re: Php Shoutbox Tutorial

    The last post was over 8 months ago.
    Reply With Quote Reply With Quote
  19. #7
    unclekyky's Avatar
    Join Date
    Sep 2004
    Age
    22
    Posts
    5,184
    Rep Power
    13
  20. unclekyky is on a distinguished road
  21. Re: Php Shoutbox Tutorial

    This tutorial was from back in 2005, before AJAX corroded our perceptions of what a shoutbox is. Why does a shoutbox need to auto-refresh? That is a negligible feature for something that is not supposed to be used as a formal discussion platform.

    Anyway, I wouldn't recommend following this tutorial. It works, but it appears to rely on register_globals to be on and doesn't sanitize input.
    Spore-Game - The Ultimate Spore Fan-Site
    Abnegating Avunculicide Since 1601 | YC Wiki - "Quidquid latine dictum sit, altum sonatur."
    Reply With Quote Reply With Quote

Similar Threads

  1. PHP Tutorial for beginners
    By YoungCoder in forum PHP Articles
    Replies: 19
    Last Post: 04-23-2006, 02:31 PM
  2. PHP Tutorial - Logging Visitor details
    By YoungCoder in forum PHP Articles
    Replies: 11
    Last Post: 02-23-2006, 08:13 PM
  3. What is PHP?
    By wizard in forum PHP Articles
    Replies: 4
    Last Post: 11-27-2005, 06:38 AM
  4. Php Syntax
    By wizard in forum PHP Articles
    Replies: 1
    Last Post: 10-06-2005, 01:53 AM
  5. PHP Tutorial Ch #1
    By omanofmysteryp in forum PHP Articles
    Replies: 0
    Last Post: 10-25-2004, 10:09 PM