插入输入类型数据,但使用sql

时间:2019-02-26 14:12:04

标签: mysql mysqli

我的SQL插入查询失败,这是插入语句:

    INSERT INTO 0_sales_orders 
    ( order_no
    , type
    , debtor_no
    , trans_type
    , branch_code
    , customer_ref
    , reference
    , comments
    , ord_date
    , order_type
    , ship_via
    , deliver_to
    , delivery_address
    , contact_phone
    , freight_cost
    , from_stk_loc
    , delivery_date
    , payment_terms
    , total
    , prep_amount
    , ship_from
    ) VALUES 
    ('2'
    ,'0'
    ,'1'
    , '30'
    ,'2'
    ,''
    ,'002/2019'
    ,''
    ,'2018-12-31'
    ,'1'
    ,'1'
    ,'A'
    ,'Makati'
    ,'9224622988'
    ,'0'
    ,'DEF'
    ,'2019-01-01'
    ,'4'
    ,'0')

在数据库中插入ship_form会导致错误,我不知道为什么?

我添加到数据库的代码:

    $sql = "
    INSERT INTO ".TB_PREF."sales_orders 
    (order_no
    , type
    , debtor_no
    , trans_type
    , branch_code
    , customer_ref
    , reference
    , comments
    , ord_date
    , order_type
    , ship_via
    , deliver_to
    , delivery_address
    , contact_phone
    , freight_cost
    , from_stk_loc
    , delivery_date
    , payment_terms
    , total
    , prep_amount
    , ship_from
    ) VALUES 
    (" .db_escape($order_no) . "
    ," .db_escape($order_type) . "
    ," .db_escape($order->customer_id) ."
    ," .db_escape($order->trans_type) . "
    ," .db_escape($order->Branch) . "
    ,".db_escape($order->cust_ref) ."
    ,".db_escape($order->reference) ."
    ,".db_escape($order->Comments) ."
    ,'" .date2sql($order->document_date) . "'
    , " .db_escape($order->sales_type) . "
    , " .db_escape($order->ship_via)."
    ," .db_escape($order->deliver_to) . "
    ," .db_escape($order->delivery_address) . "
    , " .db_escape($order->phone) . "
    , " .db_escape($order->freight_cost) ."
    , " . db_escape($order->Location) ."
    , " .db_escape($del_date) . "
    ," .db_escape($order->payment) . "
    ," .db_escape($total). 
    ")"
    ;

    db_escape($ship_from). ")";
    db_escape($order->prep_amount).")";

1 个答案:

答案 0 :(得分:-1)

这不是sql问题...

请查看生成SQL查询的方式...

db_escape($ total)之后,您要关闭方括号并添加;到行尾,因此 ship_from和prep_amount 在$ sql变量中不存在...同样,当您修复ship_from和prep_amount的检查顺序时,因为上面您以不同的顺序定义了它(ship_from需要在prep_amount之前)