24 Des 2011

How to make a shoutbox for your website

Just for your information, nowadays every website has a shoutbox, it's a facilities that the website give to the visitor so the visitor can talk each other, i've done this when i build my website for a task that my lecturer give to me, so here the script :
<html>
<head>
<title>Shoutbox</title>
</head>
<body>


<?php
mysql_connect('localhost','root','root');
mysql_select_db('(your_database)');
if($submit){
$time=date("h:ia d/j/y");
$ok=mysql_query("INSERT INTO shoutbox(id,name,message,time) VALUES ('NULL','$name','$message','$time')");
}
$ok=mysql_query("select * from shoutbox order by id desc limit 5");
while($r=mysql_fetch_array($hasil))
{
$time=$r['time'];
$id=$r['id'];
$name=$r['name'];
$message=$r['message'];
?>
<? echo $time ?><br>
<? echo $name ?><br>
<? echo $message ?><br>
<?
}
?>
<form method="post" action="<? echo $php_self ?>">
Name : <input type="text" name="name"><br>
  Message: <textarea name="Message"></textarea><br>
<input type="submit" name="submit" value="Send">
<input type="reset" name="reset" value="Cancle">
<form>
</body>
</html>

As you can see, this is mix of html and php, so.... you have to save it with "......".php and by the way, you have to make the database and the table inside the database so this program will work properly. thanks :)

Tidak ada komentar:

Posting Komentar