Simple Shoutbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Simple Shoutbox

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

    id
    username
    message



    Here we are making the shoutbox color fields, and tables.

    shoutbox.php
    Code:
    //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 = mysqf_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>
    All that does is displays the shoutbox but we need it to add the shouts and display the fields.

    sfield.php
    Code:
    <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>
    Now here is what adds the shout:

    addshout.php
    Code:
    <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.
Working...
X