The new person's message board

Source: Internet
Author: User
The new person's message board, faster contact MySQL in the "adding and deleting". Seeking guidance, there are many shortcomings, I hope that we learn more in the process of improvement, to share.
The table name of the database is Weibo, which contains the ID (auto-Grow remember to select Auto_increment in phpMyAdmin), nickname (alias varchar), dates (dateTime), content (contents, text), Hits (int)
    1. Include ("conn.php");
    2. Mysql_set_charset (' UTF8 ');
    3. if (!empty ($_post[' Sub ')) {
    4. $name = $_post[' nickname '); The obtained field is converted to a variable
    5. $content = $_post[' content '];
    6. $sql = "INSERT into ' Weibo ' (' nickname ', ' dates ', ' content ') VALUES (' $name ', now (), ' $content ')"; Database statements, corresponding to the nickname,dates in the database (showing the publication time), content
    7. Executes the MySQL statement and returns a message notification if execution succeeds.
    8. if (mysql_query ($sql)) {
    9. Echo ("Insert succeeded");
    10. }else {//fail similarly
    11. Echo ("Insert Failed"). Mysql_error ();
    12. }
    13. }
    14. ?>
    15. Message page
Copy Code
    1. Set up administrator, password, and connected data tables to connect to the database
    2. $local = ' localhost ';
    3. $dbname = ' root ';
    4. $passwd = ' 3363064 ';
    5. $db = ' Weibo ';
    6. Mysql_connect ($local, $dbname, $passwd) or Die ("Falie");
    7. mysql_select_db ($DB);
    8. Test connection, if connection database is successful, output Yes, fail Faile
    9. if ($query) {
    10. Echo ("yes");
    11. }else {
    12. echo "Faile";
    13. // }
    14. ?>
Copy Code
    1. Delete Page
    2. Include ("conn.php");
    3. Delete a database sentence
    4. if (!empty ($_get[' del '))) {//Use Get to Get del field
    5. $del = $_get[' del ']; Convert the obtained field to a variable
    6. $sql = "Delete from ' Weibo ' where id= ' $del '"; Deleted MySQL statement, delete from table name, conditional ID equals ' del ' obtained from index.php
    7. $query =mysql_query ($sql);
    8. if ($query) {//determines if the MySQL statement is executed successfully and prompts.
    9. Echo ("delete succeeded");
    10. Header ("Refresh:5;url= ' index.php '");
    11. }else {
    12. Echo ("Failed ..."). Mysql_error ();
    13. }
    14. }
    15. ?>
Copy Code
  1. Include ("conn.php");
  2. if (!empty ($_get[' id '))) {//If the obtained ID is not empty, start executing the following statement
  3. $sql = "Select *from Weibo where id = '". $_get[' id ']. "'";
  4. $query = mysql_query ($sql);
  5. $rs = Mysql_fetch_array ($query);
  6. }
  7. if (!empty ($_post[' Sub '))) {//if the sub obtained from the form is not empty, execute the following statement
  8. $name = $_post[' nickname '); The obtained field is converted to a variable
  9. $content = $_post[' content '];
  10. $hid = $_post[' hid '];
  11. $mysql = "UPDATE ' WEIBO ' SET ' nickname ' = ' $name ', ' content ' = ' $content ' where id= ' $hid '";
  12. if (mysql_query ($mysql)) {
  13. Echo ("Insert succeeded");
  14. Header ("refresh:3;url=index.php");
  15. }else {
  16. Echo ("Insert Failed"). Mysql_error ();
  17. }
  18. }
  19. ?>
  20. Message page
Copy Code
    1. message content
    2. !--? php
    3. include ("conn.php");
    4. mysql_set_charset ("UTF8");
    5. $sql = "SELECT * from ' Weibo '";
    6. $query = mysql_query ($sql);
    7. while ($rs = Mysql_fetch_array ($query)) {
    8. ?
    9. > Username: !--? php echo ($rs [' nickname ']);?--> > Delete > Edit
      Date: !--? php echo ($rs [' dates '),?--
      contents: !--? PHP EC Ho ($rs [' content ');?--"
    10. "!--? php }
    11. ";
Copy Code
    1. Include ("conn.php"); Connecting to a database
    2. if (!empty ($_get[' id ')) {//Get ID in index, use get
    3. $sql = "Select *from Weibo where id = '". $_get[' id ']. "'"; Execute the database statement and select the database as Weibo, provided the ID equals the ID obtained from index.php
    4. $query = mysql_query ($sql);
    5. $rs = Mysql_fetch_array ($query); Read the table in the database, in the form of an array.
    6. The following is a click-through database statement that adds hits to the table, and hits equals +1 per browse.
    7. $sqlhits = "Update Weibo set hits=hits+1 where id = '". $_get[' id ']. "'";
    8. mysql_query ($sqlhits);
    9. }
    10. ?>
    11. User name:

    12. Release Date:

    13. Number of Hits:

    14. Content:
Copy Code
  • Related Article

    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.