$wpdb not being defined in function: Fatal error: Call to a member function query() on a non-object

Okay, new solution. First off, I’d recommend making the link a submit button and making the name something unique: <submit name ‘del_gallery’ /> Then in the code of your admin page: include ‘ga-functions.php’; //checks to see if certain button was pressed if(isset($_REQUEST[‘del_gallery’] && isset($_GET[‘gallery_id’]) ) { $gallery_id = $_GET[‘gallery_id’]; delete_gallery($gallery_id); wp_redirect( $_SERVER[‘HTTP_REFERER’] ); exit(); }

301 Redirect Code

Assuming that the url parsing is correct and the data is actually set up correctly in the DB I think your SQL query is wrong. My suggestion is that you replace it by calling wp_query() api with the relevant parameters. Another suggestion that might not be a bug is not to use guid, as it … Read more

how to use $wpdb->prepare to update a custom table

When you look at the Codex article on $wpdb, then you will see that your current usage is correct. The last argument array( ‘%s’, ‘%d’, ‘%s’ ) already indicates that there is something like sprintf/printf going on in the background. The $wpdb->prepare() method isn’t needed for every other method. The ones that need it: $wpdb->query() … Read more

$wpdb->prepare with ON DUPLICATE KEY UPDATE

It’s my fault. Got the solution after @Otto’s comment: Do you actually have a duplicate key here? What is the structure of user_req and what are the keys and indexes? Here’s how my SQL query should be: INSERT INTO {$wpdb->prefix}user_req ( user_id, post_id ) VALUES ( %d, %d ) WHERE NOT EXISTS ( SELECT * … Read more

Problem in inserting row to custom database table

The simplest thing to do here is remove the: ‘id’ => “”, from the data array. Also, to simplify your database creation, you don’t need to do your get_var(), you can just change your SQL command to: CREATE TABLE IF NOT EXISTS $table_name This way you let the db handle creation of the table without … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)