尝试通过获取数据库错误错误号1054来添加新客户

时间:2018-11-01 15:13:08

标签: codeigniter

enter image description here这是我在控制器中的添加功能

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

添加新客户时出现此错误

    public function add($type = 'billing'){
    if ($type == 'billing') {

        $submenu = 'add_bill_to_customer';
        $pageTitle = 'Add Bill To Customer';
    } else if ($type == 'shed') {

        $submenu = 'add_pickup_drop_customer';
        $pageTitle = 'Add Pickup Drop Customer';
    } else if ($type == 'shipper') {
        $submenu = 'add_shipper_customer';
        $pageTitle = 'Add Shipper Customer';
    } else {
        $submenu = '';
        $pageTitle = 'Add Customer'; 
    }
    $record = json_decode('{"id":null,"name":"", "name_2":"","company":"","address":"","city":"","state":"","zip":"","contact":"","contact_ext":"","fax":"","email":"","contact_2":"","contact_ext_2":"","sales":"","notes":"","type":"2","invoicing_method":"2", "payment_plan_days":"3", "is_active":"0","lane_lists":"","is_deleted":"0","approved":"0","approved_date":null,"comment":null,"unserialized_lanes":[],"since":"","unserialized_comment":[]}');
    $this->data=array('page_title'=>$pageTitle, 'record'=>$record,'main_menu'=>'customers','submenu'=>$submenu);
    layout($this,'customers/add');
}

此功能可以正常使用

我的模型函数

    <div id="container">
    <h1>A Database Error Occurred</h1>
    <p>Error Number: 1054</p><p>Unknown column 'contact_ext_2' in 'field list'</p><p>INSERT INTO `customers` (`name`, `company`, `address`, `city`, `state`, `zip`, `contact`, `contact_ext`, `contact_2`, `contact_ext_2`, `email`, `fax`, `notes`, `invoicing_method`, `has_same_address`, `mailing_address`, `mailing_city`, `mailing_state`, `mailing_zip`, `is_active`, `approved`, `approved_date`, `lane_lists`, `created_at`, `created_by`) VALUES ('MAN', 'Helllo Somthing ', '7057 N LA PAZ AVE', 'FRESNO', 'CA', '93722', '1-209-683-9325', '', '1-020-396-3932', '', 'AMAN1381SINGH@GMAIL.COM', '1-023-369-9632', 'HFKLHF FAFJAS ;LFA', '2', '1', '7057 N LA PAZ AVE', 'FRESNO', 'CA', '93722', '0', '0', NULL, 'a:1:{i:0;O:8:\"stdClass\":6:{s:10:\"from_state\";s:2:\"HI\";s:8:\"to_state\";s:2:\"CT\";s:10:\"to_state_2\";s:2:\"CO\";s:10:\"to_state_3\";s:0:\"\";s:10:\"to_state_4\";s:0:\"\";s:10:\"to_state_5\";s:0:\"\";}}', 1541084737, '24')</p><p>Filename: modules/admin/models/Admin_model.php</p><p>Line Number: 79</p>    </div>

1 个答案:

答案 0 :(得分:0)

错误非常简单地表示您的json解码数组中的contact_ext_2不是数据库中的列。我认为这是错误地添加在前端的某个位置。您可以在将数据推送到模型之前通过unset($record['contact_ext_2'])取消设置列(我在您的代码中看不到)。

更新:

查看您的数据库后,我看到它是您想要的字段,但是您对它的命名不正确!应该是contact_2_ext,而您有contact_ext_2。重命名它,它应该可以正常工作!