You did everything right with the globalize, the error message is just telling you that you called a function on $wpdb which does not exists.
Just check prior you do that $wpdb contains the object you’re intersted in:
if (is_object($wpdb) && is_a($wpdb, 'wpdb')) {
$result = $wpdb->insert( 'wp_weights', array( 'user_id' => $userid, 'current_weight' => $weight ), array( '%d', '%d' ) );
}
Alternatively you can add this below the global line to learn more:
global $wpdb;
var_dump($wpdb); // dump variable type and contents.
Additionally try:
require_once( ABSPATH . 'wp-load.php' );
global $wpdb;
You might not have wordpress ready to provide what you need in $wpdb.
Related Posts:
- error_log() output for print_r() appearing on page
- What is the best way to monitor PHP functions/executions?
- How do I set up Debugging?
- error_log is not working as expected in functions.php file
- “Notice: Undefined variable: content” is showing [closed]
- add_sub_menu page() to be replaced by add_theme_page()
- How to show the error causing the ‘There has been a critical error on your website’?
- Warning: Invalid argument supplied for foreach() in portfolio-list.php [closed]
- How to find error in my code when the error message is pointing to WP core file?
- What might cause “junk after document element” error?
- How do you change error reporting to only show errors in WordPress?
- Mute Debug Messages from Plugins
- How to Debug WordPress
- Error message prevents access to WP
- Getting notices on fresh 3.6.1 install
- WordPress: Notice:Object of class WP_Query could not be converted to int in on line
- “Undefined index” error when saving empty array with checkboxes
- Front end empty (i.e. nothing displays); Back end looks fine; What are possible causes?
- WordPress + Buddpyress – troubleshooting server overloading
- Plugin debugging with errors in activation routine
- Unnessary character on post after restore
- How to find which plugin crashes
- WordPress won’t display errors at all
- WordPress White Screen Error
- Cannot access non-wordpress subdirectories as wordpress overrides them with a 404 error
- Change login error messages
- Suppress deprecated notices
- Notice: Undefined index: host in /var/www/html/wp-includes/canonical.php on line 445
- Notice: Constant WP_POST_REVISIONS already defined
- How to stop certain warning logging in error.log?
- PHP Catchable fatal error: Object of class WP_Error could not be converted to string
- Debug mode shows Strict Standards
- Why on Earth am I getting “undefined_index” errors?
- Displaying oEmbed errors?
- “Apache HTTP Service has stopped working” with WP Query in WordPress 2.9.2
- Where exactly do I write define( ‘WP_DEBUG’, true ) in wp-config file
- Showing “ Notice: Undefined variable:” and “ Notice: Trying to get property of non-object”
- Publishing Time – WordPress Plain White Screen with No Error
- “Can’t use function return value in write context” error
- mysqli_real_connect() – authentication method unknown to the client Warnings
- How to debug php code in hostgator cPanel
- Removing warnings and notices from production servers
- What does this error mean? WordPress database error: [MySQL server has gone away]
- Fatal error: Call to undefined function is_multisite()
- WordPress white screen with word ‘error’ [closed]
- File does not exist – wp-index.php
- REST : how do you handle the rest_no_route error?
- WordPress 5 WP REST routes – No errors
- “Undefined index” in wp-includes/media.php
- Error on moving WordPress site to Host from Local installation
- Visual editor become blank after updating an article
- Unable to get WP_DEBUG, WP_DEBUG_DISPLAY, WP_DEBUG_LOG to work
- Why can I not execute php files under the wp-includes folder?
- Headers already sent by
- Failed: Filesystem preventing downloads. ( ftpext)
- Code snippet to display ID gives critical error
- I tried to build a theme from scratch and it crashed everything
- error log bloated by add_view
- Unable to locate WordPress content directory
- WP Core Update Issue
- What’s wrong with this piece of code? [closed]
- can’t get errors
- Cannot load media and I get “PHP Warning: Invalid argument supplied for foreach(“
- Cannot upgrade to 4.0 – get SSL certificate error
- Fatal Error: get_header();
- Error when setting cookie
- Fatal Error wp-settings.php on line 119
- styles/default.css in markup, where does it come from? [closed]
- download count29.php whene loading site [closed]
- My new WordPress blog keeps refreshing in Chrome browser
- Custom Post Type Causes Error: Warning: call_user_func_array()
- How to turn off WP error handling, but turn on php error handling?
- Replace old theme that understand old css (vcex_icon_box css_animation)
- Can’t log in to WordPress wp-admin after adding code to functions.php
- White screen after migrating site, but wp-admin works fine. Disabling all plugins, applying default theme and enabling debug mode does nothing
- Error regarding invalid file permissions for upgrading WordPress version
- Suddenly get errors in admin when editing post type
- WordPress Bad Request Error 400
- How to identify which php file a plugin is using on page load?
- Why am I getting syntax error, unexpected ‘endwhile’ (T_ENDWHILE) on single.php
- The link you followed has expired. Please try again
- Dashboard widget, screen options/help doesn’t work?
- Getting amp; on every single category, post and page title. How to Remove?
- WordPress fails when my post is larger than 1400 words
- How to find the function which is outputting Array
- Seeing “error” as text on white when accessing admin
- Weird Parse Error on Uploaded File
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Why I am having error Call to undefined function get_header()?
- Fatal error: Cannot declare class WP_User_Request, because the name is already in use?
- WP Debug enabled Undefined index error in a widget
- which php or css file has generated an inline style in WordPress that overwrites my css
- Whole right area of wordpress admin dashboard not showing
- Only specific users timing out
- Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
- kali php problem [closed]
- PHP warning: Undefined array key 2 in feed.php
- WordPress Customizer not loading
- Core error when calling remove_menu_page
- WordPress Throwing Deprecated Errors on its own Files