First, you’re using prepare() wrong. Should be this:
$wpdb->prepare("SELECT Active FROM testers WHERE user_id = %s", $user_id)
Or even better (%d) represents numeric value as oppose to %s which is string:
$wpdb->prepare("SELECT Active FROM testers WHERE user_id = %d", $user_id)
If you have any debugging enabled, it will throw an error from your code. Which may make your location header not work properly.
Second, the get_var() function indeed returns null
when there are no results.
Third, setting a location: header without actually exiting afterwards may cause your header to be overwritten by something else later.
Related Posts:
- Inserting Post Meta From SQL
- How to execute mulitple statement SQL queries using $wpdb->query?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Query WordPress database by registered date and role
- Size article thumbnails and retrieve them directly from database
- wpdb_prepare with multiple or condition
- SQL Error wp_commentmeta – incorrect table definition
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- How do I get the posts within a certain year/date(with sql query)?
- Create table from array with prepare
- Why this query is not showing any result on wordpresss home page?
- Why does changing Database Table Prefixes result in loss of content?
- SQL query to set posts in bulk based on the post content
- DB prefix not updating
- I wanted to Know that how can I give ingore to 0000-00-00 in my config file
- How to create index (sql) to a meta_key?
- Delete all users meta that named: user_avatar
- The MySQL Connection could not be established., before it was joomla but i have change it into worpress
- Migrated to Namecheap, now Trouble with Database & wp-config [closed]
- export individual posts to text files or a single csv file
- SQL query : Select a thumbnail for a media
- why you don’t Implement PDO for access every thing to database
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- MySQL SELECT increment counter
- how to drop partition without dropping data in MySQL?
- Creating a search form in PHP to search a database?
- MySQL equivalent of DECODE function in Oracle
- WordPress (MyISAM) database is slow, should I switch to InnoDB?
- WordPress Database lost auto increment
- Restoring WordPress posts from database only
- Getting wrong relationship value in $args in wp_Query?
- Slow wp_term_relationships query
- How to use “TRUNCATE TABLE” MySQL statement?
- Organizing WP Pages based on old website database
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- What are conventions about the schema of the $table_prefix
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- Is deleting orphaned wp_options entries safe?
- How to solve slow WordPress site caused by attachment_metadata
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- Delete all post meta except featured image
- WooCommerce – Query for ordered products
- Large database causes slow load
- Database slowdown after update to 3.4.1
- Tons of Twitter rows in my database
- How to insert data into MySQL database from the form created in WordPress site
- Select Multiple meta_value from WP DB; Single Query
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- Is it possible to split database tables using HyperDB?
- What happens if I overwrite the current wp_options table with a backup from a week ago?
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- CRUD operations using WordPress database API
- Handling large N data in WordPress
- How to Mirror WordPress database from Remote server to Local server
- WordPress is not creating table in database after activating plugin,
- Is MariaDB’s Aria storage engine suitable for WordPress?
- Difficulty importing my live site to local
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- A MySQL DB within a MySQL DB
- How do I query wp_options for expired transient pairs with MySQL commands?
- Is there a way to recover the table wp_term_relationships?
- Trouble Migrating all data blog from WordPress.com to WordPress.org
- WordPress running SQL query to update database from form
- How to fix database error duplicate entry
- How do I convert a MySQL database from utf8mb4 to utf8 encoding?
- WPDB SQL query with prepare() returning variable, not db value
- Problems with moving my WordPress site to another domain/server
- Best practice to limit results in get_row()?
- How to migrate a database from a server to another
- Trouble running $wpdb->query() with last_insert_id
- how to encyrpt DB_PASSWORD in wp-config
- Moving WordPress site to new domain – database import [duplicate]
- Location of WP default mySQL tables creation file?
- How to display data from db in select list [closed]
- Link multiple user databases together?
- Sql query to get all metadata for a post
- Set a cron job to delete a specific database table table every midnight
- SQL database import #1046 error
- Bulk find & replace on WordPress posts/pages (minus image paths)
- How to import products in host instead of database on wordpress?
- I would like some help wth an SQL query to link posts with categories
- How do I loop/iterate through posts to edit all img tags?
- Where is the HTML-handler part in the wpdb class?
- next comment id number wordpress
- Correct and secure way to access a custom SQL database in a custom PHP template file
- Merging development site with live site
- How to retrieve user data based on role using SQL?
- Missing latest posts and options after DB migration via phpMyAdmin
- Check if a database is well installed
- live site do not update after importing sql database
- How do i get value from wp_postmeta?
- “MySQL server has gone away” since update to 3.8
- featured image not showing up with mysql_connect
- MySQL Database User: Which Privileges are needed?
- Import Excel (or csv) Table with user-data as subscribers to wordpress
- Getting deleted users in database
- Print output of Table Creation
- Uploading to WordPress Database
- Have WordPress Use a Different Database for users