The data creation method in thinkphp is a very useful feature that automatically creates data objects based on form data (especially in the case of many table fields) but sometimes the method may not work as you expect, For example, the method does not work and has not yet prompted the error message this time you have to carefully put down your code, because it is likely that you write code is not standardized or other reasons for my carelessness in the following problems:The create method fails without prompting for an error message
/** * Edit Data * @Author netfox-htl * @Email [Email protected] * @DateTime 2015-10-30t17:00:29+ 0800 */ function edit_post () { if (is_post) { print_r ($this->org_model); if ($this->org_model->create ()) { //code echo $this->org_model->_sql ();//The last SQL executed Die ("create"); } else { echo $this->org_model->_sql ();//The Last executed SQL Die ($this->org_model->geterror ());} } }
The POST request data issued by the browser edit_post the printed information
Think\Model Object
(
***
***
- )
SHOW COLUMNS FROM `table1`
As if there is nothing wrong with the above, the main thing is to get the database information (in MySQL can be performed normally) but that is if (create ()) {} code does not execute instructions that the Create method does not perform as expected, I've been looking for half an hour on the internet, and I've seen some of the other people's experiences on the web. And then I looked at the database table structure, and I seemed to understand what I had to do to change all of the table fields to lowercase and then execute to solve the problem:the value of the HTML element differs from the case of the databaseThe following rules can be used to solve the above problems in the reference network experience:
- Whether the element in HTML specifies the name attribute and the value of name is exactly the same as the value in the database (case-sensitive)
- Confirm that the data in the HTML form is correctly sent out
- Model name whether the error can be found in the corresponding table (can print the model object)
- Whether the model class and its member methods are private or protected
- Whether the model's GetError () method has errors
- Method can receive the value of the post, the value received by the post is consistent with the requested value (note case)
- Confirm compliance with Thinkphp's development specifications
If the above has not solved your problem, it is to consider your personality. Reference: ThinkPHP3.2 full Development manual data creation create Novice creates always fails cause the Create method fails and returns BOOL (FALSE) ThinkPHP3.2 full development manual Development specificationsthinkphp possible causes for automatic validation and auto-fill invalidation
From for notes (Wiz)
Resolves an issue where the thinkphp create method fails without prompting for an error message