• Resolved jomo

    (@jonathanmoorebcsorg)


    Anyone seen this type of error before:

    
    WordPress database error Table '[dbname].usermeta' doesn't exist for query INSERT INTO <code>usermeta</code>( user_id, meta_key, meta_value )
                                    VALUES ( '86', '_woocommerce_persistent_cart', ..... made by do_action('wp_ajax_nopriv_save_data'), WP_Hook->do_action, WP_Hook->apply_filters, save_data
    

    the query fails because the table should be wp_usermeta not usermeta, but its perplexing why these error have started recently..
    I’m just suspecting that it could somehow be triggered by this plugin as there isn’t much else that hooks wp_ajax_nopriv_save_data, but it may not be.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor chetnapatel

    (@chetnapatel)

    Hi,

    Thank you for sharing the error message with us.

    No, no one had reported this type of error message.

    I have checked the code and I have noticed that we have used “$wpdb->prefix” prefix before “usermeta” table. So, it should not throw this error message.

    Can you please drop us an email on “support at tychesoftwares dot freshdesk dot com” where we can check the issue?

    Regards,
    Chetna Bhutka

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    Thanks for getting back, there were a few occurrences but it’s not now reproducing, so I’ll close for now until I can reproduce it.

    Plugin Contributor chetnapatel

    (@chetnapatel)

    Hi,

    Please let me know if you can reproduce the same again.

    If you have any question regarding our plugin then let us know.

    Regards,
    Chetna Bhutka

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    It definitely is reproducing, albeit not as often as I would expect.

    the example errors are:
    [16-Jun-2018 10:04:54 UTC] Error Table ‘<mysite>_www.usermeta’ doesn’t exist de la base de datos de WordPress para la consulta INSERT INTO usermeta( user_id, meta_key, meta_value )
    VALUES ( ’93’, ‘_woocommerce_persistent_cart’,

    I don’t understand what this user_id is: there is no user and the the user_id passed is sequentially increasing with every error in a way that has nothing to do with the actual user ids.

    Tracing through your code I can see where the problem is but so far I don’t have clear what the code is trying to do or why…

    in wcal_class_guest.php
    This action is hooked only if the user is not logged in:

    if ( ! is_user_logged_in() ) {
      add_action( 'wp_ajax_nopriv_save_data', 'save_data' );
    } 

    and the function then reconfirms the user is not logged in:

    function save_data() {		
            if ( ! is_user_logged_in() ) {

    ll 272+ there is code like:

    
    if( is_multisite() ) {
     // get main site's table prefix
     $main_prefix = $wpdb->get_blog_prefix(1);
     $insert_persistent_cart = "INSERT INTO <code>&quot; . $wpdb->main_prefix . &quot;usermeta</code>( user_id, meta_key, meta_value )
        VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
      $wpdb->query( $insert_persistent_cart );
    
    } else { 
      $insert_persistent_cart = "INSERT INTO <code>&quot; . $wpdb->prefix . &quot;usermeta</code>( user_id, meta_key, meta_value )
        VALUES ( '".$user_id."', '_woocommerce_persistent_cart', '".$cart_info."' )";
       $wpdb->query( $insert_persistent_cart );
    

    Well, from the logs it looks like in certain circumstances $wpdb->get_blog_prefix(1) might not be getting the right value, but even without that, there is no real $user_id and it doesn’t seem make sense to be updating the persistent cart of a fake/random user id?

    The $user_id is an id returned from the insert of an anoymous user into ac_abandoned_cart_history_lite

    
    //Insert record in abandoned cart table for the guest user
    $user_id			 = $wpdb->insert_id;
    

    , it should not be used to update a record in the real wordpress usermeta table.

    So I’m wondering whether I can ignore or comment out this part of the code or really what is it supposed to be doing?

    Plugin Contributor chetnapatel

    (@chetnapatel)

    Hi,

    Thank you for your detailed information. We really appreciated.

    Yes, you are right. The prefix of the WordPress is not getting correct. Can you please let me know you are using our plugin on the Multisite or Single store?

    I will have to check issue at our end and then I can provide you the better solution for this. I will check on it and get back to you with an update.

    Regards,
    Chetna Bhutka

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    Yes in this case it is multisite..
    .. but the code also seems not correct for single site

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    I accidentally reread the code and spotted the error:

    
    // get main site's table prefix
    $main_prefix = $wpdb->get_blog_prefix(1);
    $insert_persistent_cart = "INSERT INTO .... $wpdb->main_prefix . 
    

    the second line should read $main_prefix not $wpdb->main_prefix which is not a property of $wpdb …. I can’t format the code exactly in this forum but you get the idea..

    Unfortunately this doesn’t change the fact that what the code is doing seems to be very wrong.. the code is trying to save the anonymous abandoned cart into the usermeta of a real user whose userid happens to be the same as the id of the record inserted into the abandoned cart table..

    • This reply was modified 7 years, 11 months ago by jomo. Reason: bad code formatting by wordpress
    • This reply was modified 7 years, 11 months ago by jomo.
    Plugin Contributor chetnapatel

    (@chetnapatel)

    Hi,

    Thank you for the solution of the issue and your cooperation.

    I have tried to replicate the issue and I am able to reproduce the same on Multisite.

    Yes, it should be “$main_prefix” instead of “$wpdb->main_prefix” prefix. I will include the same fix in our next plugin update. So, you can update the plugin to the latest version.

    Let me know if you have any further question with the plugin.

    Regards,
    Chetna Bhutka

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    Hi, this stops the error message but this is not a solution.

    Your code is saving the basket of an anonymous user into the meta data of a real user, this cannot be right.

    As explained above,
    The $user_id in the code is not a user_id, it is an id returned from the insert of an anoymous user into ac_abandoned_cart_history_lite.
    This is not a valid user id to then use for an update of the usermeta table of a real user.

    I would be delighted to be proved wrong, so if you disagree please explain what you think this code is doing instead and why code which only executes if there is no user logged in is trying to update the usermeta table.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Table usermeta doesn’t exist for query INSERT INTO `usermeta`’ is closed to new replies.