Create a shoutbox using PHP and MySQL

Source: Internet
Author: User

As a PHP developer, I was sometimes asked to make a shoutbox. If the same thing happens to you, here's a quick guide. Obviously, you want to add your own CSS to it on top, but here is the basic idea.

We need a MySQL database table and three PHP files.

First, we need a file to save the database information

---file #1: mysql.inc.php---

<?php
# Simply Shouting - ashoutboxexample
# File name:mysql.inc.php
# Description: A file to hold database info.
$host  ='localhost';
$user  ='database_user_name';
$password='database_user_password';
$name  ='database_name';
?>

Create a data table with four fields. We are named shouts. Previously you may not have this SQL file, create a php file "install.php". After this file has been used once, remember to delete it!

--File #2: install.php--

<?php
# Simply Shouting-ashoutboxexample
# File name:install.php
# Description:creates the database table.
Include the database info file
Include ("mysql.inc.php");
Connecting to a database
$connection = @mysql_connect ($host, $user, $password) or Die (Mysql_error ());
$db = @mysql_select_db ($name, $connection) or Die (Mysql_error ());
If we already have a table named "shouts", we need to delete it first.
$sql = ' DROP TABLE IF EXISTS ' shouts ';
$result = @mysql_query ($sql, $connection) or Die (Mysql_error ());
Now identify the table that does not have the same name, create it
$sql = ' CREATE TABLE ' shouts ' (
' id ' int (one) not NULL auto_increment,
' Timestamp ' timestamp not NULL DEFAULT Current_timestamp,
' shoutby ' varchar default NULL,
' Shout ' varchar default NULL,
PRIMARY KEY ' id ' (' ID ')
) Type=myisam auto_increment=1 ';
echo ' Creating table: \ ' shouts\ ' ... ';
Close connection
$result = @mysql_query ($sql, $connection) or Die (Mysql_error ()); >
<title>simply Shouting-Installation </title>
<body>
<br/>
Your installation process is complete. Please remove all installation files from your server immediately. This program contains the following installation files: <br/>
<br/>
1) install.php<br/>
<br/>
<br/>
<!--I could just send them to index.phpautomatically, but then the they ' d wonder if it created correctly or not. -->
Click <a href= "index.php" > here </a> start .

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.