Thinkphp cannot call the add and save methods.

Source: Internet
Author: User
Thinkphp cannot call the add and save methods. when thinkphp calls the add method, it prompts that http: // localhost.../insert cannot be accessed.
Public function insert () {header ('content-type: text/html; charset = utf-8 '); date_default_timezone_set ('etc/GMT-8 '); $ article = M ('article'); $ data = array (); $ data ['title'] = $ _ POST ['title']; $ data ['author'] = $ _ SESSION ['username']; $ data ['Category '] = $ _ POST ['Category']; $ data ['content'] = $ _ POST ['content']; $ data ['createtime'] = strtotime (date ("Y-m-d ")); if ($ data ['Category '] =' Select '| $ data ['title'] = '') {$ this-> error ('data writing is incomplete, please enter 'again);} $ result = $ article-> add ($ data );}

When the add method is executed, it stops. if the // add () line is executing print_r ($ data );
The data is fully output. why? if you use $ article-> execute ($ SQL)
Execute the command to insert data.


Reply to discussion (solution)

$ Article-> add ($ data );
Echo $ article-> getLastSql ();
Exit;

Paste SQL

The problem is that when you execute this sentence, you will be prompted
It is not displayed at all.

Start Debugging Mode

Modify the insert method

Public function insert (){
Die ("OK ");
}

Call Article/insert to try. What are the prompts?

Output as you said: OK
My problem is that it passes the data.
Print_r ($ data );
Without adding $ article-> add ($ data );
Everything is normal. you can output the content in the array.
I also use $ article-> execute ($ aql)
Execute SQL statements and insert them to the database.
Will the data be a problem with my php 6.0 version? And
Thinkphp conflicts. Thank you for your answers.

// If ($ data ['Category '] =' Select '| $ data ['title'] = ''){
// $ This-> error ('data writing is incomplete, please input again ');
//}
Comment out the above sentence
$ Result = $ article-> add ($ data );
Echo $ article-> getLastSql ();
Try again and check whether your model has been verified.


$ Result = $ article-> add ($ data );
Or change it
$ Result = $ article-> data ($ data)-> add ();

My model class:

 

I have been testing for a long time. Why can't I always do it? is it a configuration file problem?
Why don't I paste the add () method of my ThinkPHP model to see it?
I can read data during the test, but insertion and modification may cause problems...
Thinkphp source code add method, for guidance:
Public function add ($ data = '', $ options = array (), $ replace = false) {if (empty ($ data) {// no data is transmitted, get the value of the current data object if (! Empty ($ this-> data) {$ data = $ this-> data; // reset data $ this-> data = array ();} else {$ this-> error = L ('_ DATA_TYPE_INVALID _'); return false ;}// analysis expression $ options = $ this-> _ parseOptions ($ options ); // data processing $ data = $ this-> _ facade ($ data); if (false ===$ this-> _ before_insert ($ data, $ options )) {return false;} // write data to the database $ result = $ this-> db-> insert ($ data, $ options, $ replace); if (false! ==$ Result) {$ insertId = $ this-> getLastInsID (); if ($ insertId) {// Insert ID $ data [$ this-> getPk ()] = $ insertId; $ this-> _ after_insert ($ data, $ options ); return $ insertId;} $ this-> _ after_insert ($ data, $ options);} return $ result ;}

The problem is that no records are found in the log file.

You can

Public function insert ($ data, $ options = array (), $ replace = false) {$ values = $ fields = array (); $ this-> model = $ options ['model']; foreach ($ data as $ key => $ val) {$ value = $ this-> parseValue ($ val ); if (is_scalar ($ value) {// filter non-standard data $ values [] = $ value; $ fields [] = $ this-> parseKey ($ key );}} $ SQL = ($ replace? 'Replace ': 'insert '). 'into '. $ this-> parseTable ($ options ['table']). '('. implode (',', $ fields ). ') VALUES ('. implode (',', $ values ). ')'; $ SQL. = $ this-> parseLock (isset ($ options ['lock'])? $ Options ['lock']: false); return $ this-> execute ($ SQL );}
Check whether the data is correct one by one
You can use execute to insert, which only indicates that your handwritten SQL command is correct.
If the add method fails to be inserted, it indicates that an error occurred while assembling SQL commands.

How can I debug this? No...

I can execute it in another environment. Is there a problem with my appserv or the PHP version?

I can use php5.2.8 of another user, but php6.0 has a problem...

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.