![](/img/trans.png)
[英]only can insert first and second value other value cannot insert in database. how to solve this?
[英]CodeIgniter: first query runs successfully, second fails to change the database. Same value, different tables
$ customer_number是从xml文件中获取的,由于我添加了新代码,因此需要对其进行清理以确保它确实是一个INT(我只是想缩小原因)。
将其清除后存储在上述变量名中(如果我回显此变量,则会显示一个数字)。 然后将其放置在两个数组中,以分别针对exp_store_orders和exp_members表进行两个单独的查询。
第一个查询执行顺利。 使用exp_store_order表中的$ customer_number值可以很好地更新account_number。
但是,第二个较小的查询根本无法更新exp_members表中的account_number字段。
如果我将$ updateData2数组中的变量替换为一个简单的数字(例如“ 1”),则第二个查询将执行应做的事情。 然后,使用exp_members更新account_number字段。
我并没有真正知道发生了什么。我不知道如何将它清楚地当作INT并在第一个array \\ first查询中工作,但在第二个数组中却绝对不做任何操作(没有错误!)。
任何帮助将不胜感激。
//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);
}
编辑:当我更改代码并执行以下操作:
$updateData2 = array(
'AS400_account_number' => $xml->customer_number //$customer_number
);
我收到以下错误:
错误号:1064
您的SQL语法有误; 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ WHERE
member_id
= 1”附近使用更新
exp_members
SETAS400_account_number
= WHEREmember_id
= 1
$updateData2 = array(
'account_number' => $customer_number
);
删除$ customer_number周围的引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.