Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: Simple Shoutbox

  1. #1
    Banned
    Join Date
    Feb 2008
    Location
    USA
    Posts
    61
    Thanks
    15
    Thanked 1 Time in 1 Post

    Simple Shoutbox

    Hey. Here is a shout box I made. Soon when I learn Ajax I'll make it an Ajax shout box.


    Sorry I don't have it where it automatically makes the tables :/

    Ok here we go.

    Go into PHP my admin and make a table called: shoutbox
    Then make the fields:

    id
    username
    message




    PHP Code:
    //Here we are making the shoutbox color fields, and tables.

    shoutbox.php
    Make sure you have the database called "config.php"
    <?php include("sfield.php"); ?>
    <?php 
    include("config.php"); ?>
    <?php 
    //This part is where it shows "Admin CP" and "View Full Shoutbox"
    ?>
          <span class="style1">
            <a href="/administratorcp">Admin CP</a> | </span> <a href="viewfullsbox.php">View Full Shoutbox
            </a>
        | <a href="index.php">Refresh
        </a>
        </form></td>
      </tr>
      <tr>
        <td height="32" valign="top"><p class="style3"><?php 
        $result 
    mysql_query("SELECT * FROM shoutbox order by id DESC LIMIT 5")
        or die(
    mysql_error()); 
        echo 
    "<table border='0'>";
    // keeps getting the next row until there are no more to get
    while($row mysql_fetch_array$result )) {
        
    // Print out the contents of each row into a table
        
    echo "<tr><td>"
        echo 
    $row['username']; echo ": "; echo $row['message'];
        echo 
    "</tr><td>"
        
        echo 
    "</hr></tr>"


    echo 
    "</table>";
    ?>
          
        &nbsp;</p></td>
      </tr>
    </table>




    sfield.php
    //All that does is displays the shoutbox but we need it to add the shouts and display the fields.
    <?php require_once("config.php"); ?>
    <style type="text/css">
    <!--
    .style3 {color: #000000}
    body,td,th {
        color: #000000;
    }
    -->
    </style>

    <table width="838" border="1" cellpadding="0" bgcolor="#EAF9E3" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="834" height="32" valign="top"><form name="form1" method="post" action="addshout.php">
          <label>
            <input name="username" width="335" type="text" id="username" value="Username">
            </label>
          <label>
            <input name="message" width="335" type="text" id="message" value="Message">
            </label>
          <label>
            <input type="submit" name="submit" width="500" id="submit" value="Shout">
            </label>



    addshout.php

    //Now here is what adds the shout:
    <script type="text/javascript">
    <!--
    function delayer(){
        window.location = "index.php"
    }
    //-->
    </script>
    </head>
    <body onLoad="setTimeout('delayer()', 0)">
    <?php require_once("shoutbox.php"); ?>
    <?php 
    require_once("config.php"); ?>
    <?php
    $username 
    $_POST['username'];
    $message  $_POST['message'];

    mysql_query("INSERT INTO shoutbox(username, message) VALUES('$username', '$message')")
    or die(
    mysql_error()); ?>
    <html>
    <head>
    That will automatically redirect you to index.php which I'm guessing your s box will be on the index like mine. You may change the location to where you want it.



    That wraps up the tutorial of my new shoutbox.
    Please rate this thread and give me some reputation if this shoutbox is cool.


    Thanks and Good Luck!
    Last edited by Dfraz; 04-24-2008 at 05:30 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by Dfraz View Post
    Sorry I don't have it where it automatically makes the tables :/
    If you browse to the table in phpMyAdmin you can click the Export tab, and at least post the schema so people and just run the query.
    Quote Originally Posted by Dfraz View Post
    PHP Code:
    //Make sure you have the database called "config.php"
    <?php include("sfield.php"); ?>
    <?php 
    include("config.php"); ?>
    You need to post the config.php code(remove your database username/password) so other people can use your script without much effort(especially new people). Also, you don't need to, and shouldn't, keep opening/closing PHP tags after each line like that. You only need to open one, and don't close it until you need to output some HTML or whatever:
    PHP Code:
    <?php
    include("sfield.php");
    include(
    "config.php");
    //This part is where it shows "Admin CP" and "View Full Shoutbox"
    ?>
          <span class="style1">
    You have a typo here(and you can use mysql_fetch_assoc() if you don't need the numerical index of the fields):
    Code:
    while($row = mysqf_fetch_array( $result )) {
    You should be sanitizing this input:
    Quote Originally Posted by Dfraz View Post
    PHP Code:
    $username $_POST['username'];
    $message  $_POST['message']; 
    See mysql_real_escape_string().
    After you fix these things I can delete my post. Thanks for your submission, though.

  • Users who have thanked Inigoesdr for this post:

    Dfraz (04-23-2008)

  • #3
    Banned
    Join Date
    Feb 2008
    Location
    USA
    Posts
    61
    Thanks
    15
    Thanked 1 Time in 1 Post
    Fixed

    Thanks for telling me that, I guess my mouse slipped or something and put that "f" instead of "l"

    Thanks

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    the presentation is important, is more easy to understand how is made and how can be used, so make a [ php] [ /php] for each file, you can edit the post,

    filename.php:
    PHP Code:
    // happy coding, :) 
    also, I have no idea what a shoutbox is, probably I make some but I don't know how it's call, . Conclusion, try to describe shortly what it is and how can help me,

    regards

  • Users who have thanked oesxyl for this post:

    Dfraz (04-24-2008)

  • #5
    Banned
    Join Date
    Feb 2008
    Location
    USA
    Posts
    61
    Thanks
    15
    Thanked 1 Time in 1 Post
    Ok, A shoutbox is like a chat box. But some people call it shout-box and some call it chat box. There both similar.

    First see a LIVE preview here: http://www.octi-might.info/index.php

    NOW I have it where if you're not logged in it shows up in the shout-box as a guest. If you're logged in it will show as your username.

    Administrators and soon moderators will be able to delete shouts and clear all shouts.

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    it's hard to keep it simple,
    I see that you post some question to the forum, I try to help you here:

    you have users, messages and sessions, so you need IMO, thre tables:

    users:
    id - uniq, pk and fk
    username
    rol - admin, moderator, guest and normal users

    messages:
    id - uniq, pk
    user_id, = users.id
    message

    sessions:
    id - uniq, pk
    user_id, users.id
    state - online/offline

    now you can start writing sql query for each operations you have:
    - login
    - logout
    - add user
    - delete user
    - change user rol
    - add message
    - delete message
    ....

    any time you add a new operation probably you need to modify the tables structure, add new fields, ....

    when you have all this done you can design the interface, pages you need.

    I hope this help you and thank you for the explanation about shoutbox.

    regards

  • Users who have thanked oesxyl for this post:

    Dfraz (04-24-2008)

  • #7
    Banned
    Join Date
    Feb 2008
    Location
    USA
    Posts
    61
    Thanks
    15
    Thanked 1 Time in 1 Post
    I'll try soon. But first of all, How can I restrict people from there user control panel if they are not logged in?

    I think it's something like:

    PHP Code:
     <? $username
    else
    php restrict access  ?>

    Plese help me out.
    Thanks

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    you make the submit button disabled, and don't make it enbaled only if the user is not a guest.

    PHP Code:
    <?php
    if(condition to be admin/moderator/normal user){
    ?>
    <input type="submit".... />
    <?pgp
    }else{
    ?>
    <input type="submit" .... disabled="yes"/>
    <?php
    }
    ?>
    Also don't forget to check again after submit if the user is admin/moderator or normal user and not a guest.

    regards
    Last edited by oesxyl; 04-24-2008 at 07:28 PM.

  • Users who have thanked oesxyl for this post:

    Dfraz (04-24-2008)

  • #9
    Banned
    Join Date
    Feb 2008
    Location
    USA
    Posts
    61
    Thanks
    15
    Thanked 1 Time in 1 Post
    Woo nice, Thanks.

    But also I forgot how to make it where you can restrict people who are not logged in.

    If I'm logged in it will be a normal user cp. If I'm logged out it will say "Sorry you must be logged in"

    Do you know how to do this?

    Thanks

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dfraz View Post
    Woo nice, Thanks.

    But also I forgot how to make it where you can restrict people who are not logged in.
    you must implement the mechanism, that's why I suggest to redesign. If you start from interface it's hard to make it work after.

    If I'm logged in it will be a normal user cp. If I'm logged out it will say "Sorry you must be logged in"

    Do you know how to do this?

    Thanks
    PHP Code:
    <?php
    if(condition to be admin/moderator/normal user){
    ?>
    <input type="submit".... />
    <?pgp
    }else{
    ?>
    <input type="submit" .... disabled="yes"/>
    <p>You must be ......</p>
    <?php
    }
    ?>
    You don't know if a user is admin/moderator or normal user if is not logged in, so you must check that first.

    regards
    Last edited by oesxyl; 04-24-2008 at 07:40 PM.

  • #11
    Banned
    Join Date
    Feb 2008
    Location
    USA
    Posts
    61
    Thanks
    15
    Thanked 1 Time in 1 Post
    That's not how I've seen it about a year ago.

    It was something simillar to what I posted above. But thanks for your help anyways

  • #12
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dfraz View Post
    That's not how I've seen it about a year ago.

    It was something simillar to what I posted above. But thanks for your help anyways
    the link you post, have a Login/Register, 5th from left to right on menu bar, and probably it store last 5 message somewhere.
    If you are not logged in, it display the message as Guest user.

    Edit:
    could be something like:
    PHP Code:
    if(!isset($username) || (isset($username) && !loggedin($username))){
      
    $username "Guest";

    you must write a function loggedin to check if the user is or not logged.

    regards
    Last edited by oesxyl; 04-24-2008 at 08:00 PM.

  • Users who have thanked oesxyl for this post:

    Dfraz (04-24-2008)

  • #13
    Banned
    Join Date
    Feb 2008
    Location
    USA
    Posts
    61
    Thanks
    15
    Thanked 1 Time in 1 Post
    I got it fixed. Thanks btw.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •