A php message board instance (source code download)

Source: Internet
Author: User
Tags character set php file

1. Create a folder named "msgboard" under the root directory of your PHP.

Create a "msglist. php" file under "msgboard"


Data table structure can be imported directly.

 

The code is as follows: Copy code
Create table 'msgboard '(
'Id' int (10) not null AUTO_INCREMENT,
'Username' varchar (50) character set latin1 not null,
'Sex' tinyint (1) not null default '1 ',
'MSG 'text character set latin1 not null,
Primary key ('id ')
) ENGINE = MyISAM AUTO_INCREMENT = 1 default charset = utf8;


Msglist. php file, including adding, deleting, and modifying messages

 

The code is as follows: Copy code

<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> My Message Board </title>
</Head>
<Body>
<? Php
$ Username = isset ($ _ REQUEST ['username'])? $ _ REQUEST ['username']: ''; // name
$ Sex = isset ($ _ REQUEST ['Sex '])? Intval ($ _ REQUEST ['sex']): 1; // gender
$ Msg = isset ($ _ REQUEST ['MSG '])? $ _ REQUEST ['MSG ']: ''; // Leave a message

 
 
Mysql_connect ("127.0.0.1", "root", "lzy"); // link
Mysql_select_db ("test"); // select a database
 
If (! Empty ($ username )&&! Empty ($ msg ))
 {
Mysql_query ("insert into msgboard (username, sex, msg) VALUES ('$ username',' $ sex', '$ msg ')");
 }
Else
 {
Echo "incorrect input <br/> ";
 }
 
$ Source = mysql_query ("SELECT * FROM msgboard order by id DESC ");
$ Result = array ();
 
?>
<Table border = "1" width = "1000">
<Tr align = "center">
& Lt; td width = "10%" & gt; Name & lt;/td & gt;
<Td width = "10%"> Gender </td>
<Td width = "80%"> Message Content </td>
</Tr>
<Tr>
<? Php
While ($ row = mysql_fetch_array ($ source ))
  {
Echo '<td>'. $ row ['username']. '</td> ';
Echo '<td>'. ($ row ['sex'] = 1? 'Male': 'Female ').' </td> ';
Echo '<td>'. $ row ['MSG '].' </td> ';
  }
?>
</Tr>
</Table> <p/>
 
<Form action = "msglist. php" method = "POST">
<Table width = "1000" align = "left">
<Tr>
& Lt; td width = "100%" & gt;
Name: <input type = "text" name = "username" value = "/>
</Td>
</Tr>
<Tr>
& Lt; td width = "100%" & gt;
Gender: Male <input type = "radio" name = "sex" value = "1" checked = "checked"/> & nbsp;
Female <input type = "radio" name = "sex" value = "0"/>
</Td>
</Tr>
<Tr>
& Lt; td width = "100%" & gt;
Leave a message: <br/> <textarea name = "msg" rows = "5" cols = "100"> </textarea>
</Td>
</Tr>
<Tr>
& Lt; td width = "100%" & gt;
<Input type = "submit" value = "submit"/>
</Td>
</Tr>
</Table>
</Form>
</Body>
</Html>

A php message board instance Download: http://file.111cn.net/download/2013/06/08/msgboard.rar

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.