An example of a php message board

Source: Internet
Author: User
The message board can be said to be a small WEB application that all php beginners will practice. below I will share an example of a php message board I have written with you.

The message board can be said to be a small WEB application that all php beginners will practice. below I will share an example of a php message board I wrote with you, for more information, see references.

1. create a folder named "msgboard" under the root directory of your PHP. create a "msglist. php" file under "msgboard". you can directly import the data table structure.

The instance code is as follows:

  1. Create table 'msgboard '(
  2. 'Id' int (10) not null AUTO_INCREMENT,
  3. 'Username' varchar (50) character set latin1 not null,
  4. 'Sex' tinyint (1) not null default '1 ',
  5. 'MSG 'text character set latin1 not null,
  6. Primary key ('id ')
  7. ) ENGINE = MyISAM AUTO_INCREMENT = 1 default charset = utf8;

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

The instance code is as follows:

  1.  
  2.  
  3. My message board 
  4.  
  5.  
  6. $ Username = isset ($ _ REQUEST ['username'])? $ _ REQUEST ['username']: ''; // name
  7. $ Sex = isset ($ _ REQUEST ['Sex '])? Intval ($ _ REQUEST ['sex']): 1; // gender
  8. $ Msg = isset ($ _ REQUEST ['MSG '])? $ _ REQUEST ['MSG ']: ''; // Leave a message
  9.  
  10.  
  11. Mysql_connect ("127.0.0.1", "root", "lzy"); // link
  12. Mysql_select_db ("test"); // select a database
  13.  
  14. If (! Emptyempty ($ username )&&! Emptyempty ($ msg ))
  15. {
  16. Mysql_query ("insert into msgboard (username, sex, msg) VALUES ('$ username',' $ sex', '$ msg ')");
  17. }
  18. Else
  19. {
  20. Echo "incorrect input
    ";
  21. }
  22.  
  23. $ Source = mysql_query ("SELECT * FROM msgboard order by id DESC ");
  24. $ Result = array ();
  25.  
  26. ?>
  27.  
  28. Name 
  29. Gender 
  30. Message content 
  31.  
  32. While ($ row = mysql_fetch_array ($ source ))
  33. {
  34. Echo''. $ Row ['username'].'';
  35. Echo''. ($ Row ['sex'] = 1? 'Male': 'Female ').'';
  36. Echo''. $ Row ['MSG'].'';
  37. }
  38. ?>
  39.  
  40.  

     
  41.  
  42.  
  43.  

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.