Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 3 is not inserting the data
#1

(This post was last modified: 08-29-2019, 06:28 AM by ciadmin.)

I am creating the post  via angular 8, but codeigniter is not inserting  the data, please have a look of the code, that I have done.

Code:
public function  add_bankaccount()
    {

            header("Access-Control-Allow-Origin: *");
            header("Access-Control-Request-Headers: GET,POST,OPTIONS,DELETE,PUT");
            header('Access-Control-Allow-Headers: Accept,Accept-Language,Content-Language,Content-Type');
            $response= [];
            $status=0;
            $error_mess='Some error occured.';
            $success_mess='';

            $formdata = json_decode(file_get_contents('php://input'),true);

            $name=$formdata['name'];
            $bank_name=$formdata['bank_name'];
            $iban=$formdata['iban'];
            $user_id=$formdata['user_id'];
           

            $is_account_exist=get_table_data('id', 'tbl_bank', ['user_id'=>$user_id,'iban'=>$iban]);
           
            if(!empty($is_account_exist))
            {
                $status=2;
                $error_mess='Account already exist.';

            }
            else
            {

                $save_data= [];

                $save_data['name']= $name;
                $save_data['bank_name']= $bank_name;
                $save_data['iban']= $iban;
                $save_data['user_id']= $user_id;
                $save_data['status']= 1;
                $save_data['date_added']= date('Y-m-d H:i:s');
                $save_data['date_modified']= date('Y-m-d H:i:s');

                // print_r($save_data); exit;

                 

                  $this->db->insert('tbl_bank',$save_data );

                  $status=1;
                  $error_mess='';
                  $success_mess='Account added successfully.';


            }





           

            //pr($formdata); exit;


            $response['status']=$status;
            $response['error_mess']=$error_mess;
            $response['success_mess']=$success_mess;

            $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode($response));
   
    }

ERROR - 2019-08-29 15:10:57 --> Query error: Column 'name' cannot be null - Invalid query: INSERT INTO `tbl_bank` (`name`, `bank_name`, `iban`, `user_id`, `status`, `date_added`, `date_modified`) VALUES (NULL, NULL, NULL, NULL, 1, '2019-08-29 15:10:57', '2019-08-29 15:10:57')


Please suggest the solution for above.

EDIT: moderator added [ code ] tags for readability!!

Attached Files Thumbnail(s)
   
Reply


Messages In This Thread
Codeigniter 3 is not inserting the data - by asheesharyan - 08-29-2019, 06:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB