ansonphong / postworld

Wordpress Theme Development Framework
GNU General Public License v2.0
7 stars 0 forks source link

Error when saving via AJAX #63

Closed ansonphong closed 10 years ago

ansonphong commented 10 years ago

Hi Haidy, I found an issue which appears while I'm saving to a post using pw_insert_post() via pw_save_post() via AJAX. I've only been able to get the error in the JS environment.

I pinpointed it to this line in pw_insert_post() inside postworld_posts.php, since the errors disappear when I remove this line : add_record_to_post_meta($post_ID);

This refers to a function in postworld_points.php

The error is serialized as follows, but you can read between the numbers, it says something like : Wordpress DB Error - something about column count not matching.

Error : {"0":"\n","1":"\n","2":"\n","3":"\n","4":"\n","5":"\n","6":"\n","7":"\n","8":"<","9":"d","10":"i","11":"v","12":" ","13":"i","14":"d","15":"=","16":"'","17":"e","18":"r","19":"r","20":"o","21":"r","22":"'","23":">","24":"\n","25":"\t","26":"\t","27":"\t","28":"<","29":"p","30":" ","31":"c","32":"l","33":"a","34":"s","35":"s","36":"=","37":"'","38":"w","39":"p","40":"d","41":"b","42":"e","43":"r","44":"r","45":"o","46":"r","47":"'","48":">","49":"<","50":"s","51":"t","52":"r","53":"o","54":"n","55":"g","56":">","57":"W","58":"o","59":"r","60":"d","61":"P","62":"r","63":"e","64":"s","65":"s","66":" ","67":"d","68":"a","69":"t","70":"a","71":"b","72":"a","73":"s","74":"e","75":" ","76":"e","77":"r","78":"r","79":"o","80":"r","81":":","82":"<","83":"/","84":"s","85":"t","86":"r","87":"o","88":"n","89":"g","90":">","91":" ","92":"[","93":"C","94":"o","95":"l","96":"u","97":"m","98":"n","99":" ","100":"c","101":"o","102":"u","103":"n","104":"t","105":" ","106":"d","107":"o","108":"e","109":"s","110":"n","111":"&","112":"#","113":"0","114":"3","115":"9","116":";","117":"t","118":" ","119":"m","120":"a","121":"t","122":"c","123":"h","124":" ","125":"v","126":"a","127":"l","128":"u","129":"e","130":" ","131":"c","132":"o","133":"u","134":"n","135":"t","136":" ","137":"a","138":"t","139":" ","140":"r","141":"o","142":"w","143":" ","144":"1","145":"]","146":"<","147":"b","148":"r","149":" ","150":"/","151":">","152":"\n","153":"\t","154":"\t","155":"\t","156":"<","157":"c","158...:"e","194":"t","195":"a","196":" ","197":"v","198":"a","199":"l","200":"u","201":"e","202":"s","203":"(","204":"1","205":"7","206":"8","207":"6","208":"3","209":"2","210":",","211":"&","212":"#","213":"0","214":"3","215":"9","216":";","217":"p","218":"o","219":"s","220":"t","221":"_","222":"c","223":"l","224":"a","225":"s","226":"s","227":"&","228":"#","229":"0","230":"3","231":"9","232":";","233":",","234":"&","235":"#","236":"0","237":"3","238":"9","239":";","240":"s","241":"t","242":"a","243":"n","244":"d","245":"a","246":"r","247":"d","248":"&","249":"#","250":"0","251":"3","252":"9","253":";","254":",","255":"&","256":"#","257":"0","258":"3","259":"9","260":";","261":"&","262":"#","263":"0","264":"3","265":"9","266":";","267":",","268":"0","269":",","270":"0","271":",","272":"0","273":")","274":"<","275":"/","276":"c","277":"o","278":"d","279":"e","280":">","281":"<","282":"/","283":"p","284":">","285":"\n","286":"\t","287":"\t","288":"\t","289":"<","290":"/","291":"d","292":"i","293":"v","294":">","295":"{","296":"\"","297":"v","298":"e","299":"r","300":"s","301":"i","302":"o","303":"n","304":"\"","305":":","306":"\"","307":"0","308":".","309":"1","310":"\"","311":",","312":"\"","313":"s","314":"t","315":"a","316":"t","317":"u","318":"s","319":"\"","320":":","321":"2","322":"0","323":"0","324":",","325":"\"","326":"d","327":"a","328":"t","329":"a","330":"\"","331":":","332":"1","333":"7","334":"8","335":"6","336":"3","337":"2","338":"}","$promise":{},"$resolved":true}

The origin of the error is in add_record_to_post_meta($post_ID); function inside : postworld_points.php

Any ideas what's causing this? This only just became an issue since one of the last commits in the last 24 hours.

michelhabib commented 10 years ago

Phong, i couldn't test this using your edit post page http://localhost/wordpress/search/#/edit-post i get errors related to tiny mce?

however, i created another test page [get latest commit for both postworld and theme]

sample here:

postworld.controller('pwTestController',
    function pwTestController($scope, $location, $log, $attrs, $timeout, pwData) {
        // Initialize

        $scope.pwTestPost = function() {

            var post_data = {
               'post_title'    : 'hello content',
               'post_content'  :'sdsfdsfds',
               'post_status'   : 'publish',
               'post_author'   : 1,
               'post_category' : [8,39 ],
               'post_class':'test',
               'post_format' :'ggggggg',
               'link_url':'sssssss',
               'external_image' : 'fgdfgdfgdf',             
            };
            pwData.pw_save_post( post_data ).then(
                // Success
                function(response) {    
                    //alert( "RESPONSE : " + response.data );
                    $log.info('pwData.pw_save_post : saved post id: ', response.data);                    

                },
                // Failure
                function(response) {
                    //alert('error');

                }
            );

          };
          $scope.pwTestPost();
    }
);

http://localhost/wordpress/search/#/test-post we can save the post without a problem, even with the add_record_to_post_meta($post_ID); uncommented.. can you get us more details about the difference between our example above and yours? maybe some different post_data that we can try?

ansonphong commented 10 years ago

It may be working because I commented out that line in the latest commit.

If you go inside of postworld_points.php in pw_insert_post and un-comment out this line add_record_to_post_meta($post_ID);, is it still working?

phong

ansonphong commented 10 years ago

I just tried now and it produces this :

Error : {"0":"<","1":"d","2":"i","3":"v","4":" ","5":"i","6":"d","7":"=","8":"'","9":"e","10":"r","11":"r","12":"o","13":"r","14":"'","15":">","16":"\n","17":"\t","18":"\t","19":"\t","20":"<","21":"p","22":" ","23":"c","24":"l","25":"a","26":"s","27":"s","28":"=","29":"'","30":"w","31":"p","32":"d","33":"b","34":"e","35":"r","36":"r","37":"o","38":"r","39":"'","40":">","41":"<","42":"s","43":"t","44":"r","45":"o","46":"n","47":"g","48":">","49":"W","50":"o","51":"r","52":"d","53":"P","54":"r","55":"e","56":"s","57":"s","58":" ","59":"d","60":"a","61":"t","62":"a","63":"b","64":"a","65":"s","66":"e","67":" ","68":"e","69":"r","70":"r","71":"o","72":"r","73":":","74":"<","75":"/","76":"s","77":"t","78":"r","79":"o","80":"n","81":"g","82":">","83":" ","84":"[","85":"C","86":"o","87":"l","88":"u","89":"m","90":"n","91":" ","92":"c","93":"o","94":"u","95":"n","96":"t","97":" ","98":"d","99":"o","100":"e","101":"s","102":"n","103":"&","104":"#","105":"0","106":"3","107":"9","108":";","109":"t","110":" ","111":"m","112":"a","113":"t","114":"c","115":"h","116":" ","117":"v","118":"a","119":"l","120":"u","121":"e","122":" ","123":"c","124":"o","125":"u","126":"n","127":"t","128":" ","129":"a","130":"t","131":" ","132":"r","133":"o","134":"w","135":" ","136":"1","137":"]","138":"<","139":"b","140":"r","141":" ","142":"/","143":">","144":"\n","145":"\t","146":"\t","147":"\t","148":"<","149":"c","150":"o","151":"d","152":"e","153":">","154":"i","155":"n","156":"s","157":"e","158":"r","1...:"e","186":"t","187":"a","188":" ","189":"v","190":"a","191":"l","192":"u","193":"e","194":"s","195":"(","196":"1","197":"7","198":"2","199":"7","200":"0","201":"4","202":",","203":"&","204":"#","205":"0","206":"3","207":"9","208":";","209":"p","210":"o","211":"s","212":"t","213":"_","214":"c","215":"l","216":"a","217":"s","218":"s","219":"&","220":"#","221":"0","222":"3","223":"9","224":";","225":",","226":"&","227":"#","228":"0","229":"3","230":"9","231":";","232":"s","233":"t","234":"a","235":"n","236":"d","237":"a","238":"r","239":"d","240":"&","241":"#","242":"0","243":"3","244":"9","245":";","246":",","247":"&","248":"#","249":"0","250":"3","251":"9","252":";","253":"&","254":"#","255":"0","256":"3","257":"9","258":";","259":",","260":"0","261":",","262":"0","263":",","264":"0","265":")","266":"<","267":"/","268":"c","269":"o","270":"d","271":"e","272":">","273":"<","274":"/","275":"p","276":">","277":"\n","278":"\t","279":"\t","280":"\t","281":"<","282":"/","283":"d","284":"i","285":"v","286":">","287":"{","288":"\"","289":"v","290":"e","291":"r","292":"s","293":"i","294":"o","295":"n","296":"\"","297":":","298":"\"","299":"0","300":".","301":"1","302":"\"","303":",","304":"\"","305":"s","306":"t","307":"a","308":"t","309":"u","310":"s","311":"\"","312":":","313":"2","314":"0","315":"0","316":",","317":"\"","318":"d","319":"a","320":"t","321":"a","322":"\"","323":":","324":"1","325":"7","326":"2","327":"7","328":"0","329":"4","330":"}","$promise":{},"$resolved":true}

The error disappears immediately when removing this line add_record_to_post_meta($post_ID); from pw_insert_post() in postworld_posts.php

I will look more into it...

ansonphong commented 10 years ago

When I run add_record_to_post_meta() on it's own on a valid post_id, it returns this :

WordPress database error: [Column count doesn't match value count at row 1]
insert into wp_postworld_post_meta values(172704,'post_class','standard','',0,0,0)

null

The error seems to originate in the function add_record_to_post_meta()

ansonphong commented 10 years ago

I may be running on an old database model - I will update now and report back.

ansonphong commented 10 years ago

OK - confirmed, the issue was I was running on an old database structure, with a post_author column in wp_postworld_post_meta.