doutui2016
2019-08-05 07:33
浏览 162
已采纳

如何在codeigniter上更新或插入新数据

I'm setting up a rest-API on my server, and I want to update a table (i.e "comp_holding_stock"). but every time I test to post new data it returns "No item found"

Here is my controller

   public function create_comp_holding_stock(){

   $returnArr['status'] = '0';
   $returnArr['response'] = '';

   try {
       if (!$this->input->post()) {
           $returnArr['response'] = "Only POST method is allowed";
       } else {

           $holding_stock_data = array(
               'comp_id' => $this->input->post('comp_id'),
               'customer_id' => $this->input->post('customer_id'),
               'quantity' => $this->input->post('quantity'),
               'date' => date('Y-m-d H:i:s')
           );




           if (!isset($holding_stock_data)) {
            $returnArr['response'] = "Some Parameters are missing";
        } else {

            $customer = $this->Customer->save_holding_stock($holding_stock_data);

            if (!$customer) {
                $returnArr['response'] = 'No items found';
            } else {
                $returnArr['status'] = '1';
                $returnArr['response'] =  $customer;
            }
        }
    }
} catch (Exception $ex) {
    $returnArr['response'] = "Error in connection";
    $returnArr['error'] = $ex->getMessage();
}
$response = json_encode($returnArr, JSON_PRETTY_PRINT);
echo $response;

}

And here is my model below

  public function save_holding_stock($holding_stock_data)
{
    // $this->db->trans_start();

    $success = $this->db->insert('comp_holding_stock', $holding_stock_data);

 return $success;;
}

what am i doing wrong? what is the best approach to this scenarios

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题