New employee Message Board

Source: Internet
Author: User
New employee Message Board
New message board, faster access to "add, delete, modify, and query" in mysql ". I hope you can learn more about the improvement and share it with me.
The database table name is weibo and contains the id (automatically increasing, remember to select auto_increment in phpmyadmin), nickname (alias varchar), dates (dateTime), content (content, text ), hits (int)

  1. Include ("conn. php ");
  2. Mysql_set_charset ('utf8 ');
  3. If (! Empty ($ _ POST ['sub']) {
  4. $ Name = $ _ POST ['nickname']; // Convert the obtained field to a variable.
  5. $ Content = $ _ POST ['content'];
  6. $ SQL = "INSERT INTO 'Weibo '('nickname', 'dates', 'Content') VALUES (' $ name', now (), '$ content ')"; // database statement, corresponding to the database's nickname, dates (display posting time), content
  7. // Execute the mysql statement. if the execution is successful, a message notification is returned.
  8. If (mysql_query ($ SQL )){
  9. Echo ("inserted successfully ");
  10. } Else {// same as failure
  11. Echo ("insertion failed"). mysql_error ();
  12. }
  13. }
  14. ?>
  15. Message page

  1. // Set the administrator, password, and data table to connect to the database
  2. $ Local = 'localhost ';
  3. $ Dbname = 'root ';
  4. $ Passwd = '000000 ';
  5. $ Db = 'Weibo ';
  6. Mysql_connect ($ local, $ dbname, $ passwd) or die ("falie ");
  7. Mysql_select_db ($ db );
  8. // Test the connection. if the connection to the database is successful, the output is yes and faile fails.
  9. // If ($ query ){
  10. // Echo ("yes ");
  11. //} Else {
  12. // Echo "faile ";
  13. //}
  14. ?>

  1. // Delete the page
  2. Include ("conn. php ");
  3. // Delete the database statement
  4. If (! Empty ($ _ GET ['Del ']) {// Use get to GET the del field
  5. $ Del = $ _ GET ['del']; // Convert the obtained field to a variable.
  6. $ SQL = "delete from 'Weibo 'where id =' $ del '"; // The mysql statement to be deleted. delete from table name, with the condition that id is equal to from index. 'del' obtained in php'
  7. $ Query = mysql_query ($ SQL );
  8. If ($ query) {// determines whether the mysql statement is successfully executed and the prompt is displayed.
  9. Echo ("deleted successfully ");
  10. Header ("refresh: 5; url = 'index. php '");
  11. } Else {
  12. Echo ("failed..."). mysql_error ();
  13. }
  14. }
  15. ?>

  1. Include ("conn. php ");
  2. If (! Empty ($ _ GET ['id']) {// if the obtained id is not empty, run 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, run the following statement
  8. $ Name = $ _ POST ['nickname']; // Convert the obtained field 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 ("inserted successfully ");
  14. Header ("refresh: 3; url = index. php ");
  15. } Else {
  16. Echo ("insertion failed"). mysql_error ();
  17. }
  18. }
  19. ?>
  20. Message page

  1. Message content
  2. Include ("conn. php ");
  3. Mysql_set_charset ("utf8 ");
  4. $ SQL = "select * from 'Weibo "';
  5. $ Query = mysql_query ($ SQL );
  6. While ($ rs = mysql_fetch_array ($ query )){
  7. ?>
  8. "> User name: "> Delete"> Edit
    Date:
    Content:
  9. }
  10. ?>

  1. Include ("conn. php"); // connect to the database
  2. If (! Empty ($ _ GET ['id']) {// obtain the id in the index, use get
  3. $ SQL = "select * from weibo where id = '". $ _ GET ['id']. "'"; // execute the database statement, and select weibo as the database, with the condition that id is equal to the slave index. id obtained in 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 database statement of clicks. the hits is added to the table, and the hits is equal to + 1 each time you browse.
  7. $ Sqlhits = "update weibo set hits = hits + 1 where id = '". $ _ GET ['id']. "'";
  8. Mysql_query ($ sqlhits );
  9. }
  10. ?>
  11. User name:
  12. Posting time:
  13. Clicks:
  14. Content:

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.