Fatal error when using update() in $wpdb class

I am trying to update a custom table in my WordPress database, but I keep getting this error:

Fatal error: Call to a member function update() on null in /Users/jlf/project/wp-admin/controls.php on line 21

This is my PHP:

    ini_set("display_errors",1); 
    error_reporting(E_ALL);

    $accentColor    = $_POST["accentColor"];
    $donateColor    = $_POST["donateColor"];
    $donateHover    = $_POST["donateHover"];
    $ticketStatus   = $_POST["ticketStatus"];
    $logoPath       = $_POST["logoPath"];
    $characterPath  = $_POST["characterPath"];

    global $wpdb;
    $q_result = $wpdb->update(             // line 21
        'wp_nyicff', 
        array(
            'accent_color'      =>  $accentColor, 
            'donate_color'      =>  $donateColor, 
            'donate_hover'      =>  $donateHover, 
            'tickets_status'    =>  $ticketStatus, 
            'logo_path'         =>  $logoPath, 
            'character_path'     => $characterPath
            ),
        array( 'id' => 1 ), 
        array( '%s', '%s', '%s', '%s', '%s', '%s' ), 
        array( '%d' )
    );

    if ($q_result) {
        print('<script>window.location.href = "index.php";</script>');
    }
    else   {
        die(mysql_error());
        print("<br><a href='index.php'>back</a>");
    }

All of the variables echo their proper values. I’ve globalized $wpdb. What could be going wrong?


Source: wpdb

Leave a Reply