ThinkPHP completes adding data and collecting form data _ PHP Tutorial

Source: Internet
Author: User
ThinkPHP adds data and collects form data. ThinkPHP adds data and forms data collection in two ways: Array and AR, in fact, these two methods add ThinkPHP to add data and collect form data.

There are two ways to add data: Array and AR. In fact, the two methods are the same, the difference is that AR is:

// A data model represents a table.
// An object represents a piece of data.
// A field represents the attributes of an object

This is also in line with the traditional thinking habits. The following is the sample code added by data simulation:

$ Temp = D ('user'); // $ arr = array ('id' => 11, 'name' => 'Add _ using Xuning ', 'password' => md5 ('20140901'); // data is added using AR. // A data model represents a table. // An object represents a piece of data. // A field represents the attributes of an object $ temp-> name = "add_xuning"; $ temp-> password = md5 ('20140901 '); $ res = $ temp-> add (); // $ res = $ temp-> add ($ arr); if ($ res) {$ info = $ temp-> select (); $ this-> assign ('info', $ info); $ this-> display ();} else {echo "failed to add ";}}

Then, add the data in the collection form:

1: {$ smarty. const./php-weizijiaocheng-290599.html} represents the controller path for the current price.

2. there are three ways to add collected data:

Public function add_data () {if (! Empty ($ _ POST) {$ arr =$ _ POST; $ temp = D ('user'); // $ res = $ temp-> add ($ arr ); // directly add // $ temp-> id =$ _ POST ['id']; // AR add // $ temp-> name =$ _ POST ['usename']; // $ temp-> password = md5 ($ _ POST ['password']); $ temp-> create (); // create add $ res = $ temp-> add (); if ($ res) {echo "added successfully";} else {echo "failed to add ";}} else {echo "content is blank"; $ this-> display ();}}
If you have special requirements on the data, you can use the second method. The third method is efficient and secure. Generally, the second method is not recommended.

In this way, the data is added.

Adding Shard data is divided into two methods: Array and AR. In fact, these two methods are used to add shards...

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.