0

im use code php in method get to post in column 'tr_no_hp' like

$nomorhp = $this->input->get('nomor_hp');

but after i try to insert in database column cant be null. how to fix this problems

this my controllers code

$nomorhp = $this->input->get('nomor_hp');
$data = array(
                    'us_id' => $this->user->us_id,
                    'sv_id' => $voucher->sv_id,
                    'op_id' => $voucher->op_id,
                    'tr_id_plgn' => $nomor,
                    'tr_no_hp' => $nomorhp,


                );

                 $this->db->insert('transaksi', $data);
                 $trx_id =$this->db->insert_id();

and i got this eror code

Query error: Column 'tr_no_hp' cannot be null - Invalid query: INSERT INTO `transaksi`

thanks

6
  • What type is the tr_no_hp column? What PHP version are you running? Commented Sep 7, 2019 at 2:33
  • type is varchar(16) and i use PHP 5.6 Commented Sep 7, 2019 at 2:40
  • Assign default value of 'tr_no_hp' column to NULL Commented Sep 7, 2019 at 5:28
  • can u tell me more detail code default value of 'tr_no_hp' column to NULL Commented Sep 7, 2019 at 5:29
  • in your database this 'tr_no_hp' column has not default value null and $nomorhp = $this->input->get('nomor_hp'); your this code get nothing check what data sending Commented Sep 7, 2019 at 6:26

2 Answers 2

1

Assign default value of 'tr_no_hp' column to NULL in phpmyadmin

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

You can either modify you tables to allow null (but this might break other things) or set a default value.

For example:

$nomorhp = $this->input->get('nomor_hp') ?: ''; // Default to empty string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.