• Resolved danifola

    (@danifola)


    Hi, great plugin!

    I am trying some basic code to access a table and I get an error.

    This is the code:

    $id = $wpdb->get_results(“SELECT user_login FROM wpud_users WHERE ID = 1”);

    // Echo the title of the first scheduled post
    echo $id[0]->user_login;

    This is the error:

    Fatal error: Uncaught Error: Call to a member function get_results() on null in /home/ikid2684/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code:1

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Have you declared your intention to access the $wpdb global before attempting to access it?

    global $wpdb;
    
    $id = $wpdb->get_results("SELECT user_login FROM wpud_users WHERE ID = 1");
    
    // Echo the title of the first scheduled post
    echo $id[0]->user_login;
    Thread Starter danifola

    (@danifola)

    Yes, I worked it out adding the global $wpdb line.
    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Not able to do a simple SELECT from a table with Code Snippets’ is closed to new replies.