Zen Cart Logo
Forums / General Questions / error updating field in custom table

error updating field in custom table

Views: 680

Results 1 to 3 of 3
3 Oct 2012, 6:38 PM
#1
boxes avatar

boxes

New Zenner

Join Date:
Jul 2004
Posts:
37
Plugin Contributions:
0

error updating field in custom table

i'm working on a way to update some data in a custom table that updates when the cart triggers session_recreate_id

  1. i've added the table name customer2_data to database_tables.php (TABLE_CUSTOMER2_DATA)

  2. inserted the function name in sessions.php to trigger just before the whos_online_session_recreate($oldSessID, $newSessID);

customerIPfield_session_recreate($oldSessID, $newSessID);
whos_online_session_recreate($oldSessID, $newSessID);

  1. added an extra_function that sorta parallels the whos_online_session_recreate function but first checks for the customer's IP, if it finds the customer's IP in the customer2_data customerIP field, then it should update the session id in that table row too:
function customerIPfield_session_recreate($old_session, $new_session) {
  global $db;
  $customer_ip_current = $_SERVER['REMOTE_ADDR'];

$sql = "select customerIP from " . TABLE_CUSTOMER2_DATA . " where customerIP = :customer_ip_current";
$sql = $db->bindVars($sql, ':customer_ip_current', $customer_ip_current, 'noquotestring');
$result = $db->Execute($sql);

if ($result->RecordCount() > 0) {

  $sql = "UPDATE " . TABLE_CUSTOMER2_DATA . "
          SET session_id = :newSessionID 
          WHERE session_id = :oldSessionID
          AND customerIP = :customer_ip_current";
          
  $sql = $db->bindVars($sql, ':newSessionID', $new_session, 'string'); 
  $sql = $db->bindVars($sql, ':oldSessionID', $old_session, 'string'); 
  $sql = $db->bindVars($sql, ':customer_ip_current', $customer_ip_current, 'noquotestring'); 
  $db->Execute($sql);
  
} else {

//
//  
}
   
}

However, when I add something to the cart and then try to login (triggering session recreate), I get the following error:

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 '.56.789' at line 1
in:
[select customerIP from customer2_data where customerIP = 123.34.56.789]

any idea what be the issue? i've tweaked a few things but keep getting the same error

thanks

peace

3 Oct 2012, 8:50 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: error updating field in custom table

Simple. 123.34.56.789 is being treated as a number because you didn't surround it with 'quote' marks. Thus it's failing after it accepts the number of 123.34 and dies at the second decimal point because no "number" contains two decimal points.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

4 Oct 2012, 2:22 PM
#3
boxes avatar

boxes

New Zenner

Join Date:
Jul 2004
Posts:
37
Plugin Contributions:
0

Re: error updating field in custom table

thanks so much Dr, on the money :smile:

peace