Shutbox jquery refreshing comments

Source: Internet
Author: User

The database in this example is very simple and you will understand it at a glance.

Demo

XML/HTML Code
    • Shoutbox
  1. Latest Messages
      • Shoutbox. php

        PHP Code
        1. /************************
        2. CONSTANTS
        3. /************************/
        4. Define ("HOST", "localhost ");
        5. Define ("USER", "root ");
        6. Define ("PASSWORD ","");
        7. Define ("DB ","");
        8. /************************
        9. FUNCTIONS
        10. /************************/
        11. Function connect ($ db, $ user, $ password ){
        12. $ Link = @ mysql_connect ($ db, $ user, $ password );
        13. Mysql_query ("set names utf8 ;");
        14. If (! $ Link)
        15. Die ("cocould not connect:". mysql_error ());
        16. Else {
        17. $ Db = mysql_select_db (DB );
        18. If (! $ Db)
        19. Die ("cocould not select database:". mysql_error ());
        20. Else return $ link;
        21. }
        22. }
        23. Function getContent ($ link, $ num ){
        24. $ Res = @ mysql_query ("SELECT * FROM content order by updatetime desc limit". $ num, $ link );
        25. If (! $ Res)
        26. Die ("Error:". mysql_error ());
        27. Else
        28. Return $ res;
        29. }
        30. Function insertMessage ($ user, $ message ){
        31. $ Updatetime = date ("Y-m-d H: I: s", time ());
        32. $ Query = sprintf ("insert into content (name, message, updatetime) VALUES ('% s',' % s', '$ updatetime ');", mysql_real_escape_string (strip_tags ($ user), mysql_real_escape_string (strip_tags ($ message )));
        33. $ Res = @ mysql_query ($ query );
        34. If (! $ Res)
        35. Die ("Error:". mysql_error ());
        36. Else
        37. Return $ res;
        38. }
        39. /******************************
        40. MANAGE REQUESTS
        41. /******************************/
        42. If (! $ _ POST ['action']) {
        43. // We are redirecting people to our shoutbox page if they try to enter in our shoutbox. php
        44. Header ("Location: index.html ");
        45. }
        46. Else {
        47. $ Link = connect (HOST, USER, PASSWORD );
        48. Switch ($ _ POST ['action']) {
        49. Case "update ":
        50. $ Res = getContent ($ link, 20 );
        51. While ($ row = mysql_fetch_array ($ res )){
        52. $ Result. ="
        53. ". $ Row ['name']."". $ Row ['message'].". $ row ['updatetime']."
        54. ";
        55. }
        56. Echo $ result;
        57. Break;
        58. Case "insert ":
        59. Echo insertMessage ($ _ POST ['Nick '], $ _ POST ['message']);
        60. Break;
        61. }
        62. Mysql_close ($ link );
        63. }
        64. ?>
          Address: http://www.freejs.net/article_biaodan_125.html

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.