The following does not work with my custom table:

$wpdb->prepare("UPDATE $wpdb->jch_gigs 
SET available = available - %d 
WHERE ID = %d", $quantity, $item) );

But this does:

$wpdb->prepare( "UPDATE jch_gigs 
SET available = available - %d 
WHERE ID = %d", $quantity, $item) );

What am I doing wrong?

1 Answer
1

Your problem is likely that $wpdb->jch_gigs is undefined. Is jch_ the prefix of your DB tables, as defined in wp-config.php? If so, try this:

$wpdb->prepare( 
    "UPDATE {$wpdb->prefix}gigs 
    SET available = available - %d 
    WHERE ID = %d",
     $quantity, 
     $item ) 
);

wpdb class on the Codex

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *