insert data into database with codeigniter

后端 未结 9 781
臣服心动
臣服心动 2020-12-06 02:18

Trying to insert a row into my database with CodeIgniter.

My database table is Customer_Orders and the fields are CustomerName and Or

相关标签:
9条回答
  • 2020-12-06 02:32
    function saveProfile(){
        $firstname = $this->input->post('firstname');
        $lastname = $this->input->post('lastname');
        $post_data = array('firstname'=> $firstname,'lastname'=>$lastname);
        $this->db->insert('posts',$post_data);
        return $this->db->insert_id(); 
    }
    
    0 讨论(0)
  • 2020-12-06 02:33

    Check your controller:

    function order()
        $OrderLines = $this->input->post('orderlines');
        $CustomerName = $this->input->post('customer');
        $data = array(
            'OrderLines' => $OrderLines,
            'CustomerName' =>$CustomerName
        ); 
    
        $this->db->insert('Customer_Orders', $data);
    }
    
    0 讨论(0)
  • 2020-12-06 02:35

    Just insert $this->load->database(); in your model:

    function order_summary_insert($data){
        $this->load->database();
        $this->db->insert('Customer_Orders',$data);
    }
    
    0 讨论(0)
  • 2020-12-06 02:36
    function order_summary_insert()
    $OrderLines=$this->input->post('orderlines');
    $CustomerName=$this->input->post('customer');
    $data = array(
    'OrderLines'=>$OrderLines,
    'CustomerName'=>$CustomerName
    );
    
    $this->db->insert('Customer_Orders',$data);
    }
    
    0 讨论(0)
  • 2020-12-06 02:38

    Try this in your model:

    function order_summary_insert()
        $OrderLines=$this->input->post('orderlines');
        $CustomerName=$this->input->post('customer');
        $data = array(
            'OrderLines'=>$OrderLines,
            'CustomerName'=>$CustomerName
        );
    
        $this->db->insert('Customer_Orders',$data);
    }
    

    Try to use controller just to control the view and models always post your values in model. it makes easy to understand. Your controller will be:

    function new_blank_order_summary() {
        $this->sales_model->order_summary_insert($data);
        $this->load->view('sales/new_blank_order_summary');
    }
    
    0 讨论(0)
  • 2020-12-06 02:43

    Based on what I see here, you have used lowercase fieldnames in your $data array, and uppercase fieldnames in your database table.

    0 讨论(0)
提交回复
热议问题