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.
Actually, the mistake isn’t here?
$dados1['escala'] = $this->input->post("escala1_$i")
thatescala1$1
shouldn’t beescala$1
?– Marcelo Diniz
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 ]– Gabriel Silva
by chance, this your loop should not be something like this:
for ($i=0; $i<=sizeof($dados['n']); $i++) { 
 $dados['escala'] = $this->input->post("escala_$i");
 $dados['id'] = $this->input->post("id_$i");
 $this->questionariocreate_model->quest_resgate($dados['p'],$dados);
 }
– Marcelo Diniz