PHP Shoutbox Tutorial

Creator:
Michael4

This tutorial will learn you how to make a shoutbox This is the SQL query code

CREATE TABLE `shouts` ( `shoutid` INT NOT NULL AUTO_INCREMENT, `name` TEXT NOT NULL, `comment` TEXT NOT NULL PRIMARY KEY(`shoutoutid`) );

This is the shoutbox.php code



<?php 
    mysql_connect
('server','username','password'); 
    
mysql_select_db('database'); 
    echo 
"<form action='shoutbox.php' method='post'> Name: <input type='text' name='name'>
    <br/> Comment: <textarea name='comment'></textarea><br/> 
    <input type='submit' name='addshout' value='Add Shout'></form>"

        if(isset(
$_POST["addshout"])){ 
            
$queryye "INSERT INTO `shouts` (`shoutid`,`name`,`comment`) 
            VALUES ('','"
.$_POST["name"]."','".$_POST["comment"]."');"
            
$rrrr mysql_query($queryye); 
            echo 
"Your shout has been posted<br/><br/>Thank you for posting a shout"
        } 
    
$queryyry "SELECT * FROM `shouts` ORDER BY `shoutid` DESC"
    
$rrre mysql_query($queryyry); 
    while(
$rs mysql_fetch_array($rrre)){ 
    echo 
"Name: ".$rs["name"]."<br/>Comment: ".$rs["comment"]."<br/><br/>"; }
?>

I will explain the code

mysql_connect('server','username','password'); mysql_select_db('database');

Connect's to the database, you need to change server, username and password and database.

echo "<form action='shoutbox.php' method='post'> Name: <input type='text' name='name'><br/> Comment: <textarea name='comment'></textarea><br/> <input type='submit' name='addshout' value='Add Shout'></form>";

Print's the form to add a shout

if(isset($_POST["addshout"])){ $queryye = "INSERT INTO `shouts` (`shoutid`,`name`,`comment`) VALUES ('','".$_POST["name"]."','".$_POST["comment"]."');"; $rrrr = mysql_query($queryye); echo "Your shout has been posted<br/><br/>Thank you for posting a shout";

Check's to see if the Add Shout button is click, if the Add Shout button is clicked it will insert the shout in the database. It will execute the query and print a message.

Thank you for reading my PHP Shoutbox tutorial Thank you Michael

Description:
A PHP Shoutbox tutorial

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options