Jump to content


Photo
- - - - -

Simple shoutbox


  • Please log in to reply
6 replies to this topic

#1 fedekiller

fedekiller

    Young Padawan

  • Members
  • Pip
  • 18 posts

Posted 29 June 2005 - 03:00 PM

In this tutorial i will explain how to make a simple shoutbox
For this tutorial, you will need an sql host, if you dont have one, you can get it in http://freesql.org

1. Create a new table, for that, run this code
CREATE TABLE `shoutbox` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`message` longtext NOT NULL,
PRIMARY KEY  (`id`)
) TYPE=MyISAM;

2. Now make a new document and paste this code
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #000000;
}
-->
</style><table width="200" height="200" border="0">

  <tr>
    <td><iframe scrolling="auto" src="show.php">
	</iframe>
	</td>
  </tr>
</table>
<form action="shoutbox2.php" method="post">
  <p>Name<br>  
    <input name="name_txt" type="text" id="name_txt">
</p>
  <p>Message<br>
    <textarea name="message_txt" id="message_txt"></textarea>
  </p>
</p>
  <p>
    <input type="submit" name="Submit" value="blah">  
  </p>
</form>
Save it as shout.php
In that code, im bassically making the "form" and the "style"

2. Make nother document, and paste this code
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #000000;
}
-->
</style><?
$name= $_POST["name_txt"];
$message= $_POST["message_txt"];
mysql_connect("localhost","your_username","your_pass");
mysql_select_db("your_database");
MYSQL_QUERY("INSERT INTO shoutbox (id,name,message)".
      "VALUES ('NULL','$name', '$message')");
?>
<? 
echo "Shout posted, <a href=shout.php>go back</a>"
?>
Now save it as shoutbox2.php . Here i aply style too but im sending the form too

3. Make another document and paste this code
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #000000;
}
-->
</style><?
mysql_connect("freesql.org","spoono_db","pokemon") or die(mysql_error());
    mysql_select_db("spoono_db") or die(mysql_error());
    $query = "SELECT message, name
FROM shoutbox order by id DESC LIMIT 10";
    $result = mysql_query($query);
    echo "<TABLE>";
    while($r=mysql_fetch_array($result))    
    {
        echo "<TR>
            <TD><font-size: 10px;>
<strong>$r[name]</A></font></TD></strong>
        </TR>
        <TR>
            <TD><font-size: 10px;>$r[message]</font></TD>
        </TR>
        <TR>
            <TD><HR></TD>
        </TR>";
        
    }
    echo "</TABLE>"; 
?>
Here i apply style too :) but im bassicaly showing the information of the database
save this as show.php.

4. Now upload all the files to your server and enjoy your shoutbox :P

Attached Files


Edited by fedekiller, 29 June 2005 - 03:01 PM.


#2 /quit

/quit

    P2L Che

  • Members
  • PipPipPipPip
  • 1,016 posts
  • Gender:Male
  • Location:New Hampshire

Posted 29 June 2005 - 03:06 PM

Wow, nice tut, I was gonna search that on hotscripts, but now i dont have to!

#3 Donna

Donna

    Retired P2L Queen!

  • P2L Staff
  • PipPipPipPip
  • 12,330 posts
  • Gender:Female
  • Location:B.C Canada

Posted 29 June 2005 - 03:36 PM

Wow, nice tut, I was gonna search that on hotscripts, but now i dont have to!

:P http://www.pixel2lif...d=1&ss=shoutbox

#4 fedekiller

fedekiller

    Young Padawan

  • Members
  • Pip
  • 18 posts

Posted 29 June 2005 - 04:45 PM

but my code is much more easure :P

#5 Klubba

Klubba

    Young Padawan

  • Members
  • Pip
  • 24 posts
  • Location:Denmark

Posted 30 June 2005 - 07:03 AM

I don't like that you use iframes, i would had used the PHP-command; include. But nice tutorial anyways, keep up the good work :P

#6 fedekiller

fedekiller

    Young Padawan

  • Members
  • Pip
  • 18 posts

Posted 01 July 2005 - 09:13 PM

you can also make a new page and put

<?
include ("show.php")
?>

#7 eric81

eric81

    Young Padawan

  • Members
  • Pip
  • 258 posts
  • Gender:Male

Posted 02 July 2005 - 04:07 AM

why not just have it post to itself rather then using more then one page?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users