2

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?

4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.