简体   繁体   中英

CodeIgniter: first query runs successfully, second fails to change the database. Same value, different tables

$customer_number is being grabbed from an xml file and, due to new code I've added, being sanitized to ensure that it is indeed an INT (I was just trying to narrow down causes).

It's sanitized then stored in aforementioned variable name (If I echo this variable, I do get a number displayed). It is then placed into two arrays for two separate queries targeting the exp_store_orders and exp_members tables respectively.

The first query executes without a hitch. account_number is updated just fine with the value of $customer_number within the exp_store_order table.

However, the second smaller query fails to update the account_number field in the exp_members table at all.

if I replace the variable in the $updateData2 array with a simple number, such as '1', the second query does what it is supposed to do. The account_number field is then updated in exp_members.

I don't really get what's going on truth be told.. I don't get how it can clearly be an INT and work in the first array\\first query but do absolutely nothing (with no error!) in the second.

Any help would be greatly appreciated.

//searches for and grabs all xml files within the directory. Parses all elements and stores values in variables.
foreach(glob("/random/directory/listing/*xml") as $filename) {
    $xml= simplexml_load_file($filename);

    $order_id = $xml->order_id; 
    $hash = $xml->hash; 
    $timestamp = $xml->timestamp;
    $date = $xml->date;
    $time = $xml->time;
    $customer_number = $xml->customer_number;
    $customer_number = filter_var($customer_number, FILTER_SANITIZE_NUMBER_INT);
    $member_id = $xml->member_id;
    $shipping_account = $xml->shipping_account;
    $shipping_carrier = $xml->shipping_carrier;
    $shipping_tracking = $xml->shipping_tracking;
    $response = $xml->response;
    $response = filter_var($response, FILTER_SANITIZE_STRING);
    $status_update = time();



   //places variables within arrays to be fed into queries.
   $updateData = array(
       'response' => "$response",
       'order_custom2' => "$shipping_account",
       'order_custom3' => "$shipping_carrier",
       'shipping_tracking' => "$shipping_tracking",
       'order_completed_date' => "$timestamp",
       'order_status_updated' => "$status_update",
       'order_status_name' => "Shipping",
       'account_number' => "$customer_number"
   );

   $updateData2 = array(
       'account_number' => "$customer_number"
   );

   //update database with values from XML file, specifically the exp_store_orders and exp_members tables.
   $qry = $this->EE->db->where('id = '.$order_id.'')
                        ->update('exp_store_orders', $updateData); 

   $qry2 = $this->EE->db->where('member_id = '.$member_id.'')
                        ->update('exp_members', $updateData2); 

   //remove files from directory.
   //unlink($filename);
 }

Edit: When I change the code and do this:

$updateData2 = array(
       'AS400_account_number' => $xml->customer_number //$customer_number
   );

I get the following error:

Error Number: 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 'WHERE member_id = 1' at line 1

UPDATE exp_members SET AS400_account_number = WHERE member_id = 1

   $updateData2 = array(
       'account_number' => $customer_number
   );

Remove quotes around $customer_number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM