Database error: Error Number:1064 in codeigniter

Asked

Viewed 236 times

0

is making the following mistake

Error Number: 1048

Column 'scale' cannot be null

INSERT INTO teste (escala, id) VALUES (NULL, NULL)

Filename: C:/xampp/htdocs/SAO/system/database/Db_driver.php

Line Number: 691

I have tried to change several things but the error continues, my model is as follows:

class questionariocreate_model extends CI_Model{

    public function quest_create($quest_name){
        $this->load->dbforge();
        $this->db->db_select('resgate');
        $field = array(
        'escala' => array('type' => 'TEXT'),
        'id' => array('type' => 'INT'),
        );

        $this->dbforge->add_field($field);
        $this->dbforge->create_table($quest_name, TRUE);
        //$this->dbforge->add_column($quest_name,$field);

    }
    public function quest_resgate($quest_name,$dados){
        $this->db->db_select('resgates');
        $this->db->insert($quest_name,$dados);
    }

}

My controller is as follows:

public function questionario_create(){
    $this -> load-> model('questionariocreate_model');
    $dados['p'] = $this->input->post('questionario');
    $dados['n'] = $this->input->post('n');
    $dados1 = array();
    $dados2 = array();
    $dados3 = array();
    $dados4 = array();

    $this->questionariocreate_model->quest_create($dados['p']); 
    for ($i=0; $i<=sizeof($dados['n']); $i++) { 
            $dados1['escala'] = $this->input->post("escala1_$i");
            $dados1['id'] = $this->input->post("id1_$i");
            $dados2['escala'] = $this->input->post("escala_$i");
            $dados2['id'] = $this->input->post("id_$i");
            $dados3['escala'] = $this->input->post("escala_$i");
            $dados3['id'] = $this->input->post("id_$i");
            $dados4['escala'] = $this->input->post("escala_$i");
            $dados4['id'] = $this->input->post("id_$i");
            $this->questionariocreate_model->quest_resgate($dados['p'],$dados1);
            $this->questionariocreate_model->quest_resgate($dados['p'],$dados2);
            $this->questionariocreate_model->quest_resgate($dados['p'],$dados3);
            $this->questionariocreate_model->quest_resgate($dados['p'],$dados4);
    }
}

I noticed looking at inspecting element that it is receiving the values of the post scala_$i, however this giving as null at the time of saving in the database.

and another problem I’m realizing is that it’s getting all the values from my foreach, and there’s a checkbox in it so that I get only the selected ones, I don’t know exactly why these problems are occurring.

Thank you all.

  • 1

    Actually, the mistake isn’t here? $dados1['escala'] = $this->input->post("escala1_$i") that escala1$1 shouldn’t be escala$1?

  • i made this change but now the error is as follows: [You have an error in your SQL syntax; check the manual that Corresponds to your Mariadb server version for the right syntax to use near '( escala TEXT NOT NULL, id INT NOT NULL ) DEFAULT CHARACTER SET = utf8 COL' at line 1 ]

  • 1

    by chance, this your loop should not be something like this: for ($i=0; $i<=sizeof($dados['n']); $i++) { &#xA; $dados['escala'] = $this->input->post("escala_$i");&#xA; $dados['id'] = $this->input->post("id_$i");&#xA; $this->questionariocreate_model->quest_resgate($dados['p'],$dados);&#xA; }

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.