[PHP100] Message Board (i)

Source: Internet
Author: User

[Example] My message board

* * File structure:
conn.php
Database configuration
add.php
Manipulating files
list.php
List file

* * Steps

To establish a database:

phpMyAdmin

Establish database (database name):p Hp100_bbs

To perform SQL for the build table:
Message table:

You have to pay attention here, I didn't know, fool *********
Package table name/field name and so on is not at all quotation marks (single or double quotes are not) ***************
That's the short wave line (I'm so wonderful!!!) ************
CREATE TABLE ' message ' {
' id ' tinyint (1) NOT NULL auto_increment,
' User ' varchar (+) NOT NULL, # message Holders
' title ' varchar (+) NOT NULL, # Message title
' Content ' text is not NULL,
' lastdate ' date not NULL,
Primary KEY (' ID '),
} engine=innodb default Charset=utf-8 auto_increment=1;
*******
The correct SQL
CREATE TABLE IF not EXISTS ' message ' (
' id ' tinyint (1) not NULL auto_increment,
' User ' varchar (+) not NULL,
' title ' varchar (not NULL),
' Content ' text is not NULL,
' Lastdate ' date not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT Charset=utf8 auto_increment=1;

(This is a simple example, so the database can be written at the same time as the PHP code)

Below to establish a connection to PHP (conn.php)

<?php

Connecting to a database
@ is ignore error
[Email protected] mysql_connect ("localhost", "root", "") or Die ("database does not exist");
Open database (library name)
mysql_select_db ("Ph100_bbs");
Set Chinese encoding
mysql_query ("Set names ' GBK '"); Using GBK Chinese encoding

echo $conn;


After that, create a message to add PHP (add.php)


To perform data insertion into SQL:

<?php
Header ("Content-type:text/html;charset=utf-8");


Import Connection Database files
Include ("conn.php");


Finally, this is used to process submissions
if (Isset ($_post[' Sub ')) {
$sql = "INSERT into message (id,user,title,content,lastdate) VALUES (' ', ' {$_post[' user ']} ', ' {$_post[' title ']} ', ' {$_ post[' content '} ', now ()) ";
Note the $_post array call format, inside the index or need to use single quotation marks AH;
The last parameter now () is a MySQL system function that can be executed correctly on the DBMS;
Echo $sql;

$result =mysql_query ($sql)//successful, return value >1
Or Die ("Invalid query:".) Mysql_error ());

}

?>

<!--need a form below for submission--

<form action= "add.php" method= "POST" >
User: <input type= "text" name= "user" ><br>
Title: <input type= "text" name= "title" ><br>
Content: <textarea name= "Content" ></textarea><br>

Submit button <input type= "Submit" Name= "sub" value= "Post message" >


</form>

list.php********************

<?php
Header ("Content-type:text/html;charset=utf-8");
echo "Chinese";

Include ("conn.php");

?>

<table width=500 border= "0" align= "center" cellpadding= "5" cellspacing= "1" bgcolor= "#add3ef" >
<?php

$query =mysql_query ("SELECT * from message");

while ($line =mysql_fetch_array ($query))
{

?>

<tr bgcolor= "#eff3ff" >
<td> title: <?php echo $line ["title"];?></td><td> User: <?php echo $line ["User"];? ></td >
</tr>
<tr bgcolor= "#ffffff" >
<TD colspan= "2" > Content: <?php echo $line ["content"];?></td>
</tr>
<?php
}
?>

<!--//See here you should know, embedded PHP is now placed in this bracket group (<? PHP?>) in order to!!! -

</table>

[PHP100] Message Board (i)

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.