Thinkphp fails to add data to the database using the add method.

Source: Internet
Author: User
After I use the add method to submit data, the database is always unable to insert the data I want to insert. The data submitted by the html {code...} post method can be obtained in the following method, that is, add does not enter add {code...}. Where did I write the error? After I use the add method to submit data, the database is always unable to insert the data I want to insert.

Html

    

The data submitted by the post method can be obtained in the following method, that is, add is not included.
Add

Public function add () {header ("Content-Type: text/html; charset = UTF-8"); if (isset ($ _ POST ["add"]) {$ room = M ('room '); $ roominfo ['room _ id'] = $ _ POST ["room_id"]; $ roominfo ['room _ type'] =_ _ POST ["room_type"]; $ roominfo ['room _ status'] =$ _ POST ["room_status"]; $ roominfo ['room _ region'] =_ _ POST ["room_area"]; $ roominfo ['room _ cost'] =$ _ POST ["room_cost"]; $ roominfo ['room _ description'] = $ _ POST ["room_description"]; $ room-> add ($ roominfo ); echo "script" alert ('added successfully') script "; // $ this-> display (" add "); // write data here because the page with the method name as the primary is not displayed }}

Where did I go wrong?
?

Reply content:

After I use the add method to submit data, the database is always unable to insert the data I want to insert.

Html

    

The data submitted by the post method can be obtained in the following method, that is, add is not included.
Add

Public function add () {header ("Content-Type: text/html; charset = UTF-8"); if (isset ($ _ POST ["add"]) {$ room = M ('room '); $ roominfo ['room _ id'] = $ _ POST ["room_id"]; $ roominfo ['room _ type'] =_ _ POST ["room_type"]; $ roominfo ['room _ status'] =$ _ POST ["room_status"]; $ roominfo ['room _ region'] =_ _ POST ["room_area"]; $ roominfo ['room _ cost'] =$ _ POST ["room_cost"]; $ roominfo ['room _ description'] = $ _ POST ["room_description"]; $ room-> add ($ roominfo ); echo "script" alert ('added successfully') script "; // $ this-> display (" add "); // write data here because the page with the method name as the primary is not displayed }}

Where did I go wrong?
?

You can print the generated SQL statement or the error information in the database.

Check whether the database Field cache is Enabled:

Delete the field cache in Runtime/Data/_ fields/or directly Delete the entire Runtime file.

Tp has its own add () function. I wonder if it will conflict with it?
In addition, if the debugging mode is enabled, a prompt is prompted for database problems.

Var_dump $ _ POST to check whether the data is correctly received. In the add method, echo a string to check whether the method is enabled. Then, dump $ room to check whether the model has been instantiated successfully, debug show_page_trace => true on the Open configuration file page to view the generated SQL statement.

Use var_dump to check whether $ _ POST is successfully passed. Use var_dump to check if $ model-> add ($ room_info) does not return the primary key of the database table. If not, the addition fails. Use getlastsql () view the previous database statement. Check whether the field name is wrong.

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.