Zen Cart Logo
Forums / General Questions / SQL Table Error (table doesn't exist?)

SQL Table Error (table doesn't exist?)

Views: 2,302

Results 1 to 15 of 15
8 Feb 2012, 4:56 PM
#1
plymgary1 avatar

plymgary1

Zen Follower

Join Date:
Feb 2009
Posts:
121
Plugin Contributions:
0

SQL Table Error (table doesn't exist?)

Hello,

I'm trying to programme a '3 for 2' module and keep getting this error message:

1146 Table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist
in:
[ select products_id from products_3_for_2_flags where products_id = 882]

Is this trying to say I haven't got the table 'products_3_for_2_flags' in my database? Because, I have! Any ideas what's going wrong please? :)

Many thanks,

Gary:smile:

8 Feb 2012, 6:49 PM
#2
plymgary1 avatar

plymgary1

Zen Follower

Join Date:
Feb 2009
Posts:
121
Plugin Contributions:
0

Re: SQL Table Error (table doesn't exist?)

I should also say that product id 882 is also in the table so not sure why it can't find it?

I tried flushing the table too but that didn't seem to work either.

9 Feb 2012, 6:43 AM
#3
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: SQL Table Error (table doesn't exist?)

plymgary1:

keep getting this error message:

Table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist
< snip >
Is this trying to say I haven't got the table 'products_3_for_2_flags' in my database?

No. It is saying the table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist.

plymgary1:

Because, I have! Any ideas what's going wrong please? :)

The table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist. We have no way to know if table 'products_3_for_2_flags' exists or not. The error message says nothing about this table.

Cheers
Rod

9 Feb 2012, 4:29 PM
#4
plymgary1 avatar

plymgary1

Zen Follower

Join Date:
Feb 2009
Posts:
121
Plugin Contributions:
0

Re: SQL Table Error (table doesn't exist?)

RodG:

No. It is saying the table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist.

The table 'xkwies_handcrafteduk.products_3_for_2_flags' doesn't exist. We have no way to know if table 'products_3_for_2_flags' exists or not. The error message says nothing about this table.

Cheers
Rod

Thanks for your reply. :)

Oh, I thought xkwies_handcrafteduk. was the name of the DB it was trying to access and products_3_for_2_flags was the table?

Am I wrong? If so, I'll have to find a way around it. :)

10 Feb 2012, 9:36 AM
#5
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: SQL Table Error (table doesn't exist?)

plymgary1:

Thanks for your reply. :)

Oh, I thought xkwies_handcrafteduk. was the name of the DB it was trying to access and products_3_for_2_flags was the table?

Am I wrong? If so, I'll have to find a way around it. :)

Not entirely wrong, but the quotes make a huge difference in this case. In other words, 'xkwies_handcrafteduk.products_3_for_2_flags' (with quotes) is looking for a table of this name in the currently opened database.

If you remove the quotes it will indeed be looking for a table named 'products_3_for_2_flags' in the 'xkwies_handcrafteduk' database.

Does this make it clearer?

Cheers
Rod

10 Feb 2012, 10:24 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: SQL Table Error (table doesn't exist?)

plymgary1:

Thanks for your reply. :)

Oh, I thought xkwies_handcrafteduk. was the name of the DB it was trying to access and products_3_for_2_flags was the table?

Am I wrong? If so, I'll have to find a way around it. :)
plymgary1, actually you are indeed correct.

RodG missed the fact that the SQL query gives away the fact that the query is indeed looking in the xkwies_handcrafteduk database for the table named products_3_for_2_flags.

So, instead, you probably have a prefix problem.

10 Feb 2012, 11:38 AM
#7
plymgary1 avatar

plymgary1

Zen Follower

Join Date:
Feb 2009
Posts:
121
Plugin Contributions:
0

Re: SQL Table Error (table doesn't exist?)

Thanks for the replies. :)

I bet it's something really easy to fix but I just have no idea! Would someone mind taking a look at the code below from modules/order_total/ and see what the problem might be please?

<?php



  class ot_3_for_2_discount_flags {

    var $title, $output;
    var $explanation; 

    function ot_3_for_2_discount_flags() {
      $this->code = 'ot_3_for_2_discount_flags';
      $this->title = MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_TITLE;
      $this->description = MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_DESCRIPTION;
      $this->sort_order = MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_SORT_ORDER;
      $this->output = array();
    }

	function check_product($pid) {
		global $db;
		
		$sql_chk = " select products_id from products_3_for_2_flags where products_id = ". (int)$pid;
		$rs_chk = $db->Execute($sql_chk);
		
		if ($rs_chk->EOF) {
			return false;
		}
		else {
			return true;
		}
	}
	
    function print_amount($amount) {
      global $db, $order, $currencies;
      return  $currencies->format($amount, true, $order->info['currency'], $order->info['currency_value']);
    }

    function get_order_total() {
       global  $order;
       $order_total_tax = $order->info['tax'];
       $order_total = $order->info['total'];

       $order_total -= $order->info['shipping_cost'];
       $order_total -= $order->info['tax'];
       $orderTotalFull = $order_total;
       $order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax);
       return $order_total;
    }

    function process() {
       global $db, $order, $currencies;
       $od_amount = $this->calculate_deductions();
       if ($od_amount['total'] > 0) {
         $order->info['total'] = $order->info['total'] - $od_amount['total'];
         $this->title = '<a href="javascript:alert(\'' . $this->explanation . '\');">' . $this->title . '</a>'; 
         $this->output[] = array('title' => $this->title . ':',
         'text' => '-' . $currencies->format($od_amount['total'], true, $order->info['currency'], $order->info['currency_value']),
         'value' => $od_amount['total']);
       }
    }

    function calculate_deductions() {
       global $db, $order, $currencies;
	   
       $od_amount = array();
       $od_amount['tax'] = 0;

       $products = $_SESSION['cart']->get_products();

       $prod_list = array();
       $prod_list_price = array();
       $prod_list_back = array(); 
	   
       $all_items = 0;
       $all_items_price = 0;
	   
	   $disc_amount = 0;

       for ($i=0, $n=sizeof($products); $i<$n; $i++) {
	   
	   	if ($this->check_product($products[$i]['id'])) {
		
	          $price = $products[$i]['final_price'];
	          $quantity = $products[$i]['quantity'];
	
			  //$disc_amount += $this->get_disc_amount($quantity, $price);
			  
	          //$prod_list_back[$products[$i]['id']] = &$products[$i];
	          //$prod_list[$products[$i]['id']] += $quantity;
	          //$prod_list_price[$products[$i]['id']] += ($price * $quantity);
	
	          $all_items += $quantity;
	          //$all_items_price += ($price * $quantity);
		}	  
		
       }

		$disc_amount += $this->get_disc_amount($all_items, $price);
		  
       $this->explanation = YOUR_CURRENT_3_FOR_2_DISCOUNT_FLAGS . "\\n" . "\\n"; 
       $this->explanation .= "\\n\\n" . TOTAL_DISCOUNT . $this->print_amount($disc_amount); 
	   $od_amount['total'] = round($disc_amount, 2); 
       return $od_amount;
   }

   function get_disc_amount($count,$price) {
      $disc_amount = 0;
	  $new_count = $count - ($count%3);
//	  if (($count % 3) == 0) {
	  	$disc_amount = ($new_count/3) * 3;
//	  }	
      return $disc_amount; 
   } 


   function pre_confirmation_check($order_total) {
      $od_amount = $this->calculate_deductions();
      return $od_amount['total'] + $od_amount['tax'];
    }

    function credit_selection() {
      return $selection;
    }

    function collect_posts() {
    }

    function update_credit_account($i) {
    }

    function apply_credit() {
    }

    function check() {
      global $db;
      if (!isset($this->_check)) {
        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_STATUS'");
        $this->_check = $check_query->RecordCount();
      }
      return $this->_check;
    }

    function keys() {
      return array('MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_STATUS', 'MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_SORT_ORDER');
    }

    function install() {
      global $db;
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('© Gary<br /><div><a href=\"http://www.mywebsite.com\" target=\"_blank\">Website</a></div><br />This module is installed', 'MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_STATUS', 'true', '', '6', '1','zen_cfg_select_option(array(\'true\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_3_FOR_2_DISCOUNT_FLAGS_SORT_ORDER', '299', 'Sort order of display.', '6', '2', now())");
    }

    function remove() {
      global $db;
      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

  }

?>

The table products_3_for_2_flags is there too. Here's a screen cap :)

Any idea? Please? :smile:

10 Feb 2012, 11:55 PM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: SQL Table Error (table doesn't exist?)

Sounds like your configure.php is pointing to a different database than the one you're looking at in phpMyAdmin

11 Feb 2012, 5:28 AM
#9
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: SQL Table Error (table doesn't exist?)

DrByte:

Sounds like your configure.php is pointing to a different database than the one you're looking at in phpMyAdmin

My thoughts exactly.

I can't think of any other explanation. Pity the top half of the screenshot provided was missing, else we'd know for sure :)

Cheers
Rod

13 Feb 2012, 9:07 PM
#10
plymgary1 avatar

plymgary1

Zen Follower

Join Date:
Feb 2009
Posts:
121
Plugin Contributions:
0

Re: SQL Table Error (table doesn't exist?)

Sorry for the delay getting back.

I'm not sure the problem is with configure.php? There's no other connectivity problem with the db.

Here's a screenshot where you can see the table name. :)

http://www.handcrafteduk.com/screen2.jpg
13 Feb 2012, 9:15 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: SQL Table Error (table doesn't exist?)

Well, it's not going to say the table doesn't exist if it's not true.

And it's not giving you a permission-denied message, so it doesn't sound like a permissions problem.

What's the history behind this site? Do you have several databases and several db users and several db servers etc? Or has it always only been JUST ONE and never any others?

Also, please click Reply below and answer all the questions in the Posting Tips section on that page.

13 Feb 2012, 9:17 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: SQL Table Error (table doesn't exist?)

Further, I might suggest a couple code changes, for better practice.

ie: change this:$sql_chk = " select products_id from products_3_for_2_flags where products_id = ". (int)$pid;to this:```
$sql_chk = "select products_id from [B]" . DB_PREFIX . "[/B]products_3_for_2_flags where products_id = ". (int)$pid;

- remove the space at the beginning of the query
- add the DB_PREFIX
14 Feb 2012, 5:43 AM
#13
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: SQL Table Error (table doesn't exist?)

plymgary1:

I'm not sure the problem is with configure.php?

Just to be sure, could you please post the DB portion of your configure.php files (XXX out the username/password).

plymgary1:

There's no other connectivity problem with the db.

If it is pointing to a different database you probably won't notice any other 'connectivity' problems.

This has me baffled at the moment, and I don't sleep easy when I can't explain why a software problem seems to have no logical cause.
As the Dr. Says "it's not going to say the table doesn't exist if it's not true".

Computers can be mysterious things, but I've never known them to actually 'lie', or even make a mistake (even though it is true that some error messages can be a little misleading, or less than helpful).

Cheers
Rod

17 Feb 2012, 11:22 AM
#14
plymgary1 avatar

plymgary1

Zen Follower

Join Date:
Feb 2009
Posts:
121
Plugin Contributions:
0

Re: SQL Table Error (table doesn't exist?)

Hello again,

I just wanted to say thanks again for taking the time out to reply. :)

Here's the info:

from includes/configure.php

// define our database connection
  define('DB_TYPE', 'mysql');
  define('DB_PREFIX', '');
  define('DB_SERVER', 'localhost');
  define('DB_SERVER_USERNAME', 'xkwies_username');
  define('DB_SERVER_PASSWORD', 'delted for this post!');
  define('DB_DATABASE', 'xkwies_handcrafteduk');
  define('USE_PCONNECT', 'false'); // use persistent connections?
  define('STORE_SESSIONS', 'db'); // use 'db' for best support, or '' for file-based storage

from admin/includes/configure.php

// define our database connection
  define('DB_TYPE', 'mysql');
  define('DB_PREFIX', '');
  define('DB_SERVER', 'localhost');
  define('DB_SERVER_USERNAME', 'xkwies_username');
  define('DB_SERVER_PASSWORD', 'deleted');
  define('DB_DATABASE', 'xkwies_handcrafteduk');
  define('USE_PCONNECT', 'false'); // use persistent connections?
  define('STORE_SESSIONS', 'db'); // use 'db' for best support, or '' for file-based storage

It's got me stumped too! :smile:

17 Feb 2012, 1:34 PM
#15
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: SQL Table Error (table doesn't exist?)

plymgary1:

I just wanted to say thanks again for taking the time out to reply. :)

I love a ood mystery.

plymgary1:

It's got me stumped too! :smile:

Configs look OK.

Worst part is, I know I've come across something like this once before.... a long time ago. I think it had to do with the underscore and the way the server was configured, but it was such an unlikely scenario that I haven't given it a second thought since.

Did you try adding the DB_PREFIX as suggested by Dr.Byte?

If that doesn't help, perhaps a few 'echo' statements conveniently placed in the script to output the current variable and CONSTANT values may be helpful.

I'll let you know if I casn think of anthing else.

Cheers
Rod