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...