PHP's Message board

Source: Internet
Author: User

Message board or a small blog system has the following functions, writing title content and MySQL save, modify, delete.

1<?PHP2@mysql_connect("localhost:3306", "Root", "") or die("MySQL Connection failed");3@mysql_select_db("php100") or die("DB connection Failed");4     //mysql_set_charset ("GBK"); 5.2.3 above can write, correct function encoding5     mysql_query("Set names ' Gb2312_chinese_ci '");//6     mysql_query("SET NAMES ' UTF8 '");//in order to ensure that the Web page transfer Chinese characters into the database will not become garbled7?>
conn.php
1<a href= ' add.php ' > Add content </a>23<?PHP4     Header("content-type:text/html; Charset=utf-8 ");//ensure the normal display of Chinese5     include_once("conn.php");6 7     $sql= "SELECT * from ' News ' ORDER by id DESC";8     $query=mysql_query($sql);9     Ten      while($rs=Mysql_fetch_array($query)) {//perform a read down one piece of data at a time One  A?> -Echo $rs["title"]?> | -<a href= "edit.php?ed=<?php Echo$rs[' id ']?> ' > Edit </a> | the<a href= "del.php?del=<?php Echo$rs[' id ']?> ' > Delete </a> | -<li> Time: <?phpEcho $rs["Dates"]?></li> -<p><?phpEcho $rs["Contents"]?></p> - +<?php//A typical mixed-up, totally drunk. -     } +?>
index.php
1<?php//Add content Page2     Header("content-type:text/html; Charset=utf-8 ");3     include("conn.php");//introducing a connected database4 5     if(!Empty($_post[' Sub '])){6         $title=$_post[' title '];7         $con=$_post[' Con '];8         /*$sql = "CREATE TABLE news//This is the statement that created the table9         (Ten ID INT (5) Not NULL auto_increment, One PRIMARY KEY (id), A title VARCHAR (+), - dates DATE, - Contents TEXT the         )";*/ -         $sql= "INSERT INTO ' news ' (' id ', ' title ', ' dates ', ' contents ') value (null, '$title', now (), '$con‘)"; -          -         Echo $sql." <br/> "; +         mysql_query($sql); -         Echo"Insert is OK"; +     } A  at  -?> -  -<form action= "add.php" method= "POST" > -Title <input type= "text" name= "title" ><br> -Content <textarea rows= "5" cols= "name=" Con "></textarea><br> in<input type= "Submit" Name= "sub" value= "POST" > -</form>
add.php
1<?PHP2     3     include("conn.php");4     Header("content-type:text/html; Charset=utf-8 ");5     6     if(!Empty($_get[' del '])) {//in the index page, the link is followed by the del= ' $id ' can be obtained using the Get method to simply pass the information7         $d=$_get[' Del '];8         $sql= "Delete from ' news ' where ' id ' = '$d‘";9         mysql_query($sql);Ten         Echo"Delete Succeeded"; One     } A?>
del.php
1<?PHP2     include_once("conn.php");3     Header("content-type:text/html; Charset=utf-8 ");4     if(!Empty($_get[' Ed ']) {//also pass the ID with the link suffix5         $ed=$_get[' Ed '];6         $sql= "SELECT * from ' News ' where ' id ' = '$ed‘";7         $query=mysql_query($sql);8         $rs=Mysql_fetch_array($query);9?>Ten  OneEcho $rs[' title ']?> A<li> Time: <?phpEcho $rs[' Dates ']?></li> -<form method= "POST" action= "edit.php" > -<input type= "hidden" name= "hid" value= "<?php Echo$ed?> "/>//The hidden ID to pass, with the Post method, this kind of writing is also learned, and will not be displayed on the page theContent: <textarea name= "Con" rows= "5" cols= "><?php"Echo $rs[' Contents ']?></textarea> -<br><br> -<input type= "Submit" name= "Submit" value= "Modify"/> -</form> +  -<?PHP +     } A  at     if(!Empty($_post[' Submit '])) { -         $content=$_post[' Con ']; -         $hid=$_post[' HID ']; -         $sql= "Update ' news ' set ' contents ' = '$content' WHERE ' id ' = '$hid‘"; -         mysql_query($sql); -         Echo"<script>alert (' update succeeded '); location.href= ' index.php ' </script>"; in     } -      to?>
edit.php

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.