insert data into database with codeigniter

后端 未结 9 803
臣服心动
臣服心动 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:47

    It will be better for you to write your code like this.

    In your Controller Write this code.

        function new_blank_order_summary() {
         $query = $this->sales_model->order_summary_insert();
         if($query) {
            $this->load->view('sales/new_blank_order_summary'); 
        } else {
            $this->load->view('sales/data_insertion_failed');
        }
      }
    

    and in your Model

    function order_summary_insert() {
        $orderLines = trim(xss_clean($this->input->post('orderlines')));
        $customerName = trim(xss_clean($this->input->post('customer')));
        $data = array(
            'OrderLines'=>$orderLines,
            'CustomerName'=>$customerName
        );
    
        $this->db->insert('Customer_Orders',$data);
        return ($this->db->affected_rows() != 1) ? false : true;
    }
    

提交回复
热议问题