PHP form data writing MySQL code, php form writing mysql_PHP tutorial

Source: Internet
Author: User
PHP form data is written to MySQL code, and php form is written to mysql. PHP form data writes MySQL code, php form writes mysqlh1 insert operation h1? Phpif (! Isset ($ _ POST [submit]) {if no form is submitted, is a form displayed? Formaction PHP form data write MySQL code, php form write mysql
INSERT operation
         
  

Reference: http://www.cnblogs.com/roucheng/p/phpmysql.html

The above code uses different formats. I don't know which format is better.

  1. INSERT operation
  2. If (! Isset ($ _ POST ['submit ']) {
  3. // If no form is submitted, a form is displayed.
  4. ?>
  5. }
  6. Else
  7. {
  8. // If the form is submitted
  9. // Database connection parameters
  10. $ Host = "localhost ";
  11. $ User = "root ";
  12. $ Pass = "zq19890319 ";
  13. $ Db = "phpdev ";
  14. // Obtain the value in the form, check whether the value in the form complies with the standard, and escape it to prevent SQL injection.
  15. $ Country = empty ($ _ POST ['country'])? Die ("enter the country name "):
  16. Mysql_escape_string ($ _ POST ['country']);
  17. $ Animal = empty ($ _ POST ['Animal '])? Die ("Enter English name "):
  18. Mysql_escape_string ($ _ POST ['Animal ']);
  19. $ Cname = empty ($ _ POST ['cname'])? Die ("Enter Chinese name "):
  20. Mysql_escape_string ($ _ POST ['cname']);
  21. // Open the database connection hovertree.com
  22. $ Connection = mysql_connect ($ host, $ user, $ pass) or die ("Unable to connect! ");
  23. // Select a database
  24. Mysql_select_db ($ db) or die ("Unable to select database! ");
  25. // Construct an SQL query
  26. $ Query = "insert into symbols (country, animal, cname) VALUE ('$ country', '$ animal', '$ cname ')";
  27. // Execute this query
  28. $ Result = mysql_query ($ query) or die ("Error in query: $ query.". mysql_error ());
  29. // The insert record number is displayed after the insert operation is successful.
  30. Echo "the record has been inserted, mysql_insert_id () =". mysql_insert_id ();
  31. // Close the current database connection
  32. Mysql_close ($ connection );
  33. }
  34. ?>

When h1 insert operation/h1? Php if (! Isset ($ _ POST ['submit ']) {// if no form is submitted, is a form displayed? Form action = "...

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.