Simple Shoutbox

Started on the old forum in October 2009 · view the original in the archive · old links redirect here

No replies · 1,582 views · started 17 years ago · 1 min read

riderz Lead · 975 posts #1

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

//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>";
?>
      
     </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

<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

<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.


Jacques jacques@gw-designs.co.za http://coding.biz.tm Come join and lets make it a place to learn all the noobies how to code


NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close