Implementation of mysql form submission in php development to prevent repeated refreshing

Source: Internet
Author: User

The following describes how to implement mysql form submission in php development to prevent repeated refreshes. If you have encountered similar problems before, take a look.

The database is jokes and the table is jokes. Add a joke as an example.
Mysql form submission page:

 
 
  1. <HTML>
  2. <HEAD>
  3. <TITLE> Our List of Jokes </TITLE>
  4. </HEAD>
  5. <BODY>
  6.  
  7. <? Php
  8. Session_start (); // enable session
  9. $ Timetime = time ();
  10. $ Key = "sess _". $ time; // generate a random session key based on the time
  11. $ _ SESSION [$ key] = $ time; // sets the session value.
  12. ?>
  13.  
  14. <Form action = "input. php? Tjid = 1 "METHOD = POST>
  15. <P> Type your joke here: <BR>
  16. <Textarea name = "joketext" ROWS = 10 COLS = 40 WRAP> </TEXTAREA> <BR>
  17. // Pass the session key to the server for processing by hiding the form
  18. <Input type = "hidden" name = "session_key" value = "<? Php echo $ key;?> "/>
  19. <Input type = submit name = "submitjoke" VALUE = "SUBMIT">
  20. </FORM>
  21.  
  22. </BODY>
  23. </HTML>
  24.  
  25. Processing page:
  26. <HTML>
  27. <HEAD>
  28. <TITLE> Our List of Jokes </TITLE>
  29. </HEAD>
  30. <BODY>
  31. // Connect to the database:
  32. <? Php
  33. $ Dbcnx = mysql_connect ("localhost", "root ","******");
  34. If (! $ Dbcnx ){
  35. Echo ("<P> Unable to connect to ".
  36. "Database server at this time. </P> ");
  37. Exit ();
  38. }
  39. // Select the jokes database
  40. If (! @ Mysql_select_db ("jokes ")){
  41. Echo ("<P> Unable to locate the joke ".
  42. "Database at this time. </P> ");
  43. Exit ();
  44. }
  45. // Start the session:
  46. Session_start ();
  47. $ Key = $ _ POST ['session _ key'];
  48. If (! $ Key | $ _ SESSION [$ key]! = Substr ($ key, 5 )){
  49. // If the session_key parameter is not passed
  50. // Or the number after the session_key parameter value truncates sess _ does not match the session parameter value
  51. Unset ($ _ SESSION [$ key]); // deletes the session value.
  52. Echo "chu cuo la"; // then consider whether an error is prompted, or transfer to another page
  53. Exit (); // terminate page Code Execution
  54. }
  55.  
  56. // Write the data below
  57. If ("SUBMIT" ==$ _ POST ["submitjoke"]) {
  58. $ SQL = "INSERT INTO Jokes (joketext)
  59. VALUES ('$ _ POST [joketext]')
  60. ";
  61. If (mysql_query ($ SQL )){
  62. Echo ("<P> Your joke has been added. </P> ");
  63. } Else {
  64. Echo ("<P> Error adding submitted joke :".
  65. Mysql_error (). "</P> ");
  66. }
  67. // After the data operation is complete, delete the session
  68. Unset ($ _ SESSION [$ key]);
  69. }
  70. ?>
  71.  
  72. // Display joke content:
  73. <P> Here are all the jokes in our database: </P>
  74. <BLOCKQUOTE>
  75. <? Php
  76. $ Result = mysql_query (
  77. "SELECT * FROM Jokes ");
  78. If (! $ Result ){
  79. Echo ("<P> Error checking Ming query :".
  80. Mysql_error (). "</P> ");
  81. Exit ();
  82. }
  83. // Display the text of each joke in a paragraph
  84. While ($ row = mysql_fetch_array ($ result )){
  85. Echo ("<P>". $ row ["JokeText"]. "</P> ");
  86. }
  87. ?>
  88.  
  89. </BODY>
  90. </HTML>
  91.  

Simple MySQL large table backup method

Implementation of MySQL table sharding

MySQL authorization table usage example

Disadvantages of MySQL memory tables

Advantages and disadvantages of MySQL independent tablespace

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.