You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

80 lines
2.7 KiB

<?php
require_once "../header.php";
// 載入db.php來連結資料庫
//require_once "../database.php";
error_reporting(E_ALL);
ini_set("display_errors", "On");
$data = $_POST;
$table_hope_customer = 'hope_customer';
#可编辑的列
$editableColumn = [
'vol_no' => '卷号(*)',
'customer_kind' => '客户类别',
'pre_order_date' => '预定成交日',
'level' => '客户等级',
'salesman' => '营业员',
'order_province' => '下单地区',
'install_province' => '安装地区',
'sale_branch' => '营业网点',
'project_kind' => '项目类别',
'pre_delivery_date' => '预计出货日',
'city' => '市',
'area' => '县',
'lm_name' => '联系人姓名',
'lm_tel' => '联系电话',
'lm_address' => '联系人地址',
'is_strategic_customers' => '是否战略客户'
];
insert_or_uptdate($data, $table_hope_customer, $editableColumn, $link);
#echo $ins_or_update_sql;
$table_hope_project = "hope_project";
$editableColumn =
[
'vol_no' => $data['vol_no'],
'case_name' => '项目名称',
'customer_name' => '客户名称',
'address' => '项目工地地址',
'install_company' => '安装客户名称',
'track_status' => '追踪状况',
'is_repeat_customer' => '是否回头客',
'creator' => '登陆者',
'kind' => '分类',
'is_downtown' => '市中心项目',
'manufacture_company' => '机件受订公司',
'is_cross_regional' => '是否跨区域',
'strategic_customer_kind' => '战略客户类别'
];
$table_hope_project_data = [];
foreach ($data as $val) {
foreach ($editableColumn as $col => $colname) {
$table_hope_project_data[$col] = empty($data[$col]) ? null : $data[$col];
}
}
insert_or_uptdate($data, $table_hope_project, $editableColumn, $link);
function insert_or_uptdate($data, $table_name, $editableColumn, $link)
{
$table_data = [];
foreach ($data as $val) {
foreach ($editableColumn as $col => $colname) {
$table_data[$col] = empty($data[$col]) ? null : $data[$col];
}
}
$ins_or_update_sql = "insert into $table_name (" . implode(",", array_keys($table_data)) . ")
values ('" . implode("','", array_values($table_data)) . "')
ON DUPLICATE KEY UPDATE ";
$_update_field = [];
foreach ($table_data as $key => $val) {
array_push($_update_field, " $key = '" . $val . "'");
}
$ins_or_update_sql .= implode(',', $_update_field);
echo $ins_or_update_sql;
//$ins_or_update_sql .= " where vol_no ='" . $table_hope_customer_data['vol_no'] . "'";
$data = mysqli_query($link, $ins_or_update_sql);
}