WordPress database error: [Incorrect table name ''] SHOW FULL COLUMNS FROM empty table name

WordPress Database Error Help Needed

Hi everyone! I’m having trouble with a WordPress database issue. When I try to fetch data from a custom table in my template file, I keep getting this error message:

WordPress database error: [Incorrect table name ‘’] SHOW FULL COLUMNS FROM ``

I’m not sure what’s causing this problem. Here’s the PHP code I’m using:

<?php /* Template Name: checkpayment */ 
  if (!is_user_logged_in()) {
    wp_redirect(wp_login_url());
    exit;
  }
  $current_user = get_current_user_id();

  global $wpdb;

  $transactions = $wpdb->get_results("SELECT transaction_id, total_amount, payment_date FROM wp_stripe_transactions WHERE user_id = $current_user And status = 1 ORDER BY id DESC LIMIT 1");

  $recent_payment = $wpdb->get_results("SELECT transaction_id, total_amount, payment_date, processed FROM wp_payment_verification WHERE user_id = $current_user ORDER BY id DESC LIMIT 1");

  $datetime = new DateTime($transactions[0]->payment_date);
  $current_date = $datetime->format('Y-m-d');
  $current_time = $datetime->format('Y-m-d');

  if ($current_date = date('Y-m-d')) {
    if($wpdb->insert($wpdb->prefix.'payment_verification', array("user_id" => $current_user, "transaction_id" => $transactions[0]->transaction_id, "total_amount" => $transactions[0]->total_amount, "processed" => "Y", "user_email" => $transactions[0]->total_amount, "status" => $transactions[0]->status, "payment_date" => $transactions[0]->payment_date), array("%d", "%s", "%d", "%s", "%s", "%d", "%d"))){
        echo 'data inserted successfully';
    }
  }

Can someone help me figure out what’s wrong with this code? I’m fairly new to WordPress development and would appreciate any guidance. Thanks in advance!

This error happens when WordPress tries to reference a table with no name - usually means a table name variable wasn’t set up right. Besides using $wpdb->prefix properly, check if any plugins or custom functions are messing with your table names dynamically. That’ll confuse things fast. Also, don’t forget to sanitize your SQL inputs with $wpdb->prepare() - raw variables in SQL queries are asking for injection attacks. Turn on WP debug mode too, it’ll help you track down exactly what’s going wrong.

you’re mixing up table name approaches, which is confusing wordpress. use $wpdb->prefix.'stripe_transactions' instead of hardcoding ‘wp_stripe_transactions’. also, that assignment operator in your if statement should be == not = - that’s probably causing issues too. the empty table name error usually happens when wpdb can’t find the table you’re referencing.

I encountered the same issue recently. The error usually stems from how WordPress handles database table prefixes. Specifically, this error arises when an empty table name is validated. Your code mixes direct references like ‘wp_stripe_transactions’ with the proper WordPress method '$wpdb->prefix.‘payment_verification’. This inconsistency may confuse WordPress regarding the table names. Ensure you use ‘$wpdb->prefix’ for all custom tables. Additionally, I noticed a bug in your date check; you’re using ‘=’ instead of ‘==’ for comparison, which could lead to unexpected behavior.