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.