Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

SQL error when result = null


rudy905

Recommended Posts

I get an error whenever I do a search and the result is null, or no entries match my search. As an example, in the admin site in the Customers page, when I search for a customer that doesn't exist ("mysearch" in this case), here's the error I get:

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-20, 20' at line 1

 

select c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_org_type, c.customers_email_address, a.entry_country_id from customers c left join address_book a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id where c.customers_lastname like '%mysearch%' or c.customers_firstname like '%mysearch%' or c.customers_email_address like '%mysearch%' order by c.customers_lastname, c.customers_firstname limit -20, 20

 

For reference, I believe these are the relevent lines of source code (customers.php) that cause the error. Also of note, I have added a contribution for tax-exempt organizations.

 

$search = '';

if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {

$keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));

$search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "%'";

}

 

// BEGIN - Tax Exempt and Organization Discounts

// old: $customers_query_raw = "select c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_email_address, a.entry_country_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search . " order by c.customers_lastname, c.customers_firstname";

$customers_query_raw = "select c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_org_type, c.customers_email_address, a.entry_country_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search . " order by c.customers_lastname, c.customers_firstname";

// END - Tax Exempt and Organization Discounts

 

$customers_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $customers_query_raw, $customers_query_numrows);

$customers_query = tep_db_query($customers_query_raw);

while ($customers = tep_db_fetch_array($customers_query)) {

$info_query = tep_db_query("select customers_info_date_account_created as date_account_created, customers_info_date_account_last_modified as date_account_last_modified, customers_info_date_of_last_logon as date_last_logon, customers_info_number_of_logons as number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $customers['customers_id'] . "'");

$info = tep_db_fetch_array($info_query);

 

Thanks much for any help!

 

Rudy

Link to comment
Share on other sites

I get an error whenever I do a search and the result is null, or no entries match my search. As an example, in the admin site in the Customers page, when I search for a customer that doesn't exist ("mysearch" in this case), here's the error I get:

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-20, 20' at line 1

 

select c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_org_type, c.customers_email_address, a.entry_country_id from customers c left join address_book a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id where c.customers_lastname like '%mysearch%' or c.customers_firstname like '%mysearch%' or c.customers_email_address like '%mysearch%' order by c.customers_lastname, c.customers_firstname limit -20, 20

 

For reference, I believe these are the relevent lines of source code (customers.php) that cause the error. Also of note, I have added a contribution for tax-exempt organizations.

 

$search = '';

if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {

$keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));

$search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "%'";

}

 

// BEGIN - Tax Exempt and Organization Discounts

// old: $customers_query_raw = "select c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_email_address, a.entry_country_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search . " order by c.customers_lastname, c.customers_firstname";

$customers_query_raw = "select c.customers_id, c.customers_lastname, c.customers_firstname, c.customers_org_type, c.customers_email_address, a.entry_country_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_id = a.customers_id and c.customers_default_address_id = a.address_book_id " . $search . " order by c.customers_lastname, c.customers_firstname";

// END - Tax Exempt and Organization Discounts

 

$customers_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $customers_query_raw, $customers_query_numrows);

$customers_query = tep_db_query($customers_query_raw);

while ($customers = tep_db_fetch_array($customers_query)) {

$info_query = tep_db_query("select customers_info_date_account_created as date_account_created, customers_info_date_account_last_modified as date_account_last_modified, customers_info_date_of_last_logon as date_last_logon, customers_info_number_of_logons as number_of_logons from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $customers['customers_id'] . "'");

$info = tep_db_fetch_array($info_query);

 

Thanks much for any help!

 

Rudy

 

Never mind, I found the solution here:

http

://www.oscommerce.com/forums/index.php?sho...hl=1064+syntax

Thanks!

-Rudy

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...