CRUD (add, delete, modify, and query) operations of the message board developed by php

Source: Internet
Author: User

Project Structure:

Add page: Note: only focus on operations, and there is no time for the interface artist. I hope you can understand it ......

List page:

Modify page:

SQL required in the project:
Copy codeThe Code is as follows:
Create database form;

Use form;

Create table 'message '(
'Id' tinyint (1) not null auto_increment,
'User' varchar (25) not null,
'Title' varchar (50) not null,
'Content' tinytext not null,
'Lastdate' date not null,
Primary key ('id ')
) ENGINE = InnoDB default charset = gbk AUTO_INCREMENT = 1;


Conn. php
Copy codeThe Code is as follows:
<? Php
$ Conn = @ mysql_connect ("localhost", "root", "") or die ("Database Link error ");
Mysql_select_db ("form", $ conn );
Mysql_query ("set names 'gbk '");
?>

Add. php
Copy codeThe Code is as follows:
<? Php
Include 'conn. php ';
If ($ _ POST ['submit ']) {
$ SQL = "INSERT INTO message (id, user, title, content, lastdate) VALUES (NULL, '$ _ POST [user]', '$ _ POST [title]', '$ _ POST [content]', now ())";
Mysql_query ($ SQL );

// Page Jump, implemented in javascript
$ Url = "list. php ";
Echo "<script language = 'javascript 'Type = 'text/javascript '> ";
Echo "window. location. href = '$ url '";
Echo "</script> ";
}
?>
<Script type = "text/javascript">
Function checkPost (){

If (addForm. user. value = ""){
Alert ("Enter the user name ");
AddForm. user. focus ();
Return false;
}
If (addForm. title. value. length <5 ){
Alert ("the title cannot be less than five characters ");
AddForm. title. focus ();
Return false;
}
}
</Script>
<FORM name = "addForm" METHOD = "POST" ACTION = "add. php" onsubmit = "return checkPost ();">
User: <input type = "text" NAME = "user"/> <br/>
Title: <input type = "text" NAME = "title"/> <br/>
Content: <textarea name = "content" ROWS = "8" COLS = "30"> </TEXTAREA> <br/>
<Input type = "submit" name = "submit" value = "add"/> </FORM>

List. php
Copy codeThe Code is as follows:
<? Php
Include 'conn. php ';
?>
<? Php
Echo "<div align = 'center'> <a href = 'add. php'> continue adding </a> </div> ";
?>
<Table width = 500 border = "0" align = "center" cellpadding = "5" cellspacing = "1" bgcolor = "# add3ef">
<? Php
$ SQL = "select * from message order by id ";
$ Query = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ query )){
?>

<Tr bgcolor = "# eff3ff">
<Td> title: <font color = "red"> <? = $ Row [title]?> </Font> User: <font color = "red"> <? = $ Row [user]?> </Font> <div align = "right"> <a href = "preEdit. php? Id = <? = $ Row [id]?> "> Edit </a> | <a href =" delete. php? Id = <? = $ Row [id]?> "> Delete </a> </div> </td>
</Tr>
<Tr bgColor = "# ffffff">
<Td> content: <? = $ Row [content]?> </Td>
</Tr>
<Tr bgColor = "# ffffff">
<Td> <div align = "right"> published on: <? = $ Row [lastdate]?> </Div> </td>
</Tr>
<? Php }?>
</Table>

Delete. php
Copy codeThe Code is as follows:
<? Php
Include 'conn. php ';
$ Id = $ _ GET ['id'];
$ Query = "delete from message where id =". $ id;
Mysql_query ($ query );
?>
<? Php
// Page Jump, implemented in javascript
$ Url = "list. php ";
Echo "<script language = 'javascript 'Type = 'text/javascript '> ";
Echo "window. location. href = '$ url '";
Echo "</script> ";
?>

PreEdit. php
Copy codeThe Code is as follows:
<? Php
Include 'conn. php ';
$ Id = $ _ GET [id];
$ Query = "SELECT * FROM message WHERE id =". $ id;
$ Result = mysql_query ($ query );
While ($ rs = mysql_fetch_array ($ result )){
?>
<Form method = "POST" ACTION = "postEdit. php">
<Input type = "hidden" name = "id" value = "<? = $ Rs [id]?> ">
User: <input type = "text" NAME = "user" value = "<? = $ Rs [user]?> "/> <Br/>
Title: <input type = "text" NAME = "title" value = "<? = $ Rs [title]?> "/> <Br/>
Content: <textarea name = "content" ROWS = "8" COLS = "30"> <? = $ Rs [content]?> </TEXTAREA> <br/>
<Input type = "submit" name = "submit" value = "edit"/>
</FORM>
<? Php }?>

PostEdit. php
Copy codeThe Code is as follows:
<? Php
Include 'conn. php ';
$ Query = "update message set user = '$ _ POST [user]', title = '$ _ POST [title]', content = '$ _ POST [content]' where id = '$ _ POST [id]' ";
Mysql_query ($ query );
?>
<? Php
// Page Jump, implemented in javascript
$ Url = "list. php ";
Echo "<script language = 'javascript 'Type = 'text/javascript '> ";
Echo "window. location. href = '$ url '";
Echo "</script> ";
?>

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.