Simple PHP Message Board making (i)

Source: Internet
Author: User

The first is to determine their own message board requirements. For example: name, email and message content.

One. Establish a database guestbook.

CREATE TABLE IF not EXISTS ' content ' (

' id ' int (one) not NULL auto_increment,

' Name ' varchar (not NULL),

' Email ' varchar (not NULL),

' Content ' varchar (+) not NULL,

PRIMARY KEY (' id '))

Engine=myisam DEFAULT Charset=utf8 auto_increment=3;

Two. New config.php

<?php

$q = mysql_connect ("Server", "Database User", "Database Password");

if (! $q)

{

Die (' Could not connect: '. Mysql_error ());

}

mysql_query ("Set names UTF8"); Reading data with UTF8

mysql_select_db ("Guestbook", $q); Database

?>

Three. New index.php

<?php

Include ("config.php"); Introducing a database Connection file

$sql = "SELECT * from Content"; Search Data Table Content

$resule = mysql_query ($sql, $q);

?>

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

<body>

<table width= "678" align= "center" >

<tr>

<TD colspan= "2" >

</tr>

<tr>

<TD width= "586" ><a href= "index.php" > Home </a> | <a href= "liuyan.php" > Message </a></td>

</tr>

</table>

<p>

<?

while ($row =mysql_fetch_array ($resule))

{

?>

</p>

<table width= "678" border= "1" align= "center" cellpadding= "1" cellspacing= "1" >

<tr>

<TD width= "178" >NAME:<? echo $row [1]?></td>

<TD width= "223" >EMAIL:<? Echo $row [2]?></td>

</tr>

<tr>

<TD colspan= "4" ><? Echo $row [3]?></td>

</tr>

<tr>

</table>

<?

}

?>

</body>

Four. New liuyan.php

<body>

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

<table width= "678" align= "center" >

<tr>

<TD colspan= "2" >

</tr>

<tr>

<TD width= "586" ><a href= "index.php" > Home </a> | <a href= "liuyan.php" > Message </a></td>

</tr>

</table>

<table align= "center" width= "678" >

<tr>

<td>

<form name= "Form1" method= "Post" action= "post.php" >

<p>

Name:

<input name= "name" type= "text" id= "name" >

</p>

<p>email:<input type= "test" name= "email" id= "email" ></p>

<p>

Message:

</p>

<p>

<textarea name= "Content" id= "content" cols= "rows=" 5 "></textarea>

</p>

<p>

<input type= "Submit" name= "button" id= "button" value= "Submit" >

<input type= "reset" name= "Button2" id= "Button2" value= "reset" >

</p>

</form>

</td>

</tr>

</table>

</body>

Five. New post.php

<?php

Header ("content-type:text/html; Charset=utf-8 ");

Include ("config.php");

$name = $_post[' name '];

$email = $_post[' email '];

$patch = $_post[' content '];

$content = Str_replace ("

"," <br/> ", $patch);

$sql = "INSERT into content (name,email,content) VALUES (' $name ', ' $email ', ' $content ')";

mysql_query ($sql);

echo "<script>alert (' Submit success! Return to homepage. "Location.href= ' index.php ';</script>";

?>

This has succeeded in writing a message board.

Precautions
    • The database is best to use UTF8, which I write is used UTF8.

    • Input and output, to use the same encoding, otherwise it will appear garbled.

Simple PHP Message Board making (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.