WordPress.org

Make WordPress Core

Opened 4 months ago

Last modified 3 months ago

#41601 new defect (bug)

wp_update_user creates an error

Reported by: iamklaus Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8.1
Component: Users Keywords:
Focuses: Cc:

Description

See my code below. When I use wp_upadte_user within the hook "after_setup_theme", it throws an error:

[Thu Aug 10 13:08:45.503396 2017] [proxy_fcgi:error] [pid 9452] [client 10.130.52.246:56561] AH01071: Got error 'PHP message: WordPress-Datenbank-Fehler You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE user_id = 6 AND blog_id = 1' at line 1 f\xc3\xbcr Abfrage '''SELECT COUNT(id) FROM  WHERE user_id = 6 AND blog_id = 1''' von require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save, BP_Blogs_Blog->exists\nPHP message: WordPress-Datenbank-Fehler You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( user_id, blog_id ) VALUES ( 6, 1 )' at line 1 f\xc3\xbcr Abfrage INSERT INTO  ( user_id, blog_id ) VALUES ( 6, 1 ) von require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save\n', referer: http://intranetdev.rehau.org/

The sql functions being executed by this functions are missing the database table name.

Here is the code I am using inside the functions.php from my plugin:

<?php
add_action('after_setup_theme', 'ad_sso_login');
function ad_sso_login () {

    $user_id = 6;
    $website = 'http://wordpress.org';

    $user_id = wp_update_user( array( 'ID' => $user_id, 'user_url' => $website ) );

    if ( is_wp_error( $user_id ) ) {
        echo "There was an error, probably that user doesn't exist.";
    } else {
        echo "Success!";
    }
}

Change History (4)

#1 @subrataemfluence
4 months ago

Hi, I could not reproduce the issue. Worked perfectly for me.

However, the interesting thing is:

"Fehler You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE user_id = 6 AND blog_id = 1'...",

What version you are using?

Here is mine:
PHP: 5.6.22, MySQL: 5.5.57

#2 follow-up: @iamklaus
4 months ago

I am using PHP 7.1 and 10.1.23-MariaDB-9+deb9u1 for debian-linux-gnu on x86_64 (Debian 9.0).

But the error was already there when I was still using PHP 5.6.

Here is the full error message. See the bold areas: The table name is just missing.

[Thu Aug 10 16:31:55.944041 2017] [proxy_fcgi:error] [pid 10778] [client 10.130.37.117:64185] AH01071: Got error 'PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE user_id = 1706 AND blog_id = 1' at line 1 for query SELECT COUNT(id) FROM WHERE user_id = 1706 AND blog_id = 1 made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save, BP_Blogs_Blog->exists\nPHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( user_id, blog_id ) VALUES ( 1706, 1 )' at line 1 for query INSERT INTO ( user_id, blog_id ) VALUES ( 1706, 1 ) made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save\n'
[Thu Aug 10 16:32:03.102375 2017] [proxy_fcgi:error] [pid 10804] [client 10.70.36.82:57000] AH01071: Got error 'PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE user_id = 385 AND blog_id = 1' at line 1 for query SELECT COUNT(id) FROM WHERE user_id = 385 AND blog_id = 1 made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save, BP_Blogs_Blog->exists\nPHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( user_id, blog_id ) VALUES ( 385, 1 )' at line 1 for query INSERT INTO ( user_id, blog_id ) VALUES ( 385, 1 ) made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save\n'

#3 in reply to: ↑ 2 @subrataemfluence
4 months ago

Thank you for detailed error message. I can see the table name is absent. But wondering how it worked for me! I will dig into it more and see if I can reproduce the same error!

One question. Do you have contributed / third party plugins installed in your application? If yes, can you tell me what are they? I would install them at my end and see if they have any impact.

Replying to iamklaus:

I am using PHP 7.1 and 10.1.23-MariaDB-9+deb9u1 for debian-linux-gnu on x86_64 (Debian 9.0).

But the error was already there when I was still using PHP 5.6.

Here is the full error message. See the bold areas: The table name is just missing.

[Thu Aug 10 16:31:55.944041 2017] [proxy_fcgi:error] [pid 10778] [client 10.130.37.117:64185] AH01071: Got error 'PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE user_id = 1706 AND blog_id = 1' at line 1 for query SELECT COUNT(id) FROM WHERE user_id = 1706 AND blog_id = 1 made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save, BP_Blogs_Blog->exists\nPHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( user_id, blog_id ) VALUES ( 1706, 1 )' at line 1 for query INSERT INTO ( user_id, blog_id ) VALUES ( 1706, 1 ) made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save\n'
[Thu Aug 10 16:32:03.102375 2017] [proxy_fcgi:error] [pid 10804] [client 10.70.36.82:57000] AH01071: Got error 'PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE user_id = 385 AND blog_id = 1' at line 1 for query SELECT COUNT(id) FROM WHERE user_id = 385 AND blog_id = 1 made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save, BP_Blogs_Blog->exists\nPHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( user_id, blog_id ) VALUES ( 385, 1 )' at line 1 for query INSERT INTO ( user_id, blog_id ) VALUES ( 385, 1 ) made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('after_setup_theme'), WP_Hook->do_action, WP_Hook->apply_filters, ad_sso_login, logmeintothesystem, ad_sso_register_user_wrapper, ad_sso_register_user, wp_update_user, wp_insert_user, do_action('profile_update'), WP_Hook->do_action, WP_Hook->apply_filters, bp_blogs_add_user_to_blog, bp_blogs_record_blog, BP_Blogs_Blog->save\n'

Last edited 4 months ago by subrataemfluence (previous) (diff)

#4 @iamklaus
3 months ago

I just ran through my application and deactivated plugin by plugin. After deactivating BuddyPress, the error disappeared. Can you reproduce the error by installing Buddypress?

(I had the latest version of buddypress installed)

Note: See TracTickets for help on using tickets.