2
I’m trying to make a INSERT
using Codeigniter and would like to know if there is a more practical form than the one used below:
MODEL
public function set_cliente() {
$dados = array(
'codigo_cliente' => $this->input->post('cCodigocliente'),
'data_cadastro' => $this->input->post('cDatacadastro'),
'hora_cadastro' => $this->input->post('cHoracadastro'),
'funcionario' => $this->input->post('cFuncionario'),
'empresa' => $this->input->post('cEmpresa'),
'representante' => $this->input->post('cRepresentante'),
'modalidade' => $this->input->post('cModalidade')
);
$this->db->insert('tb_clientes', $dados);
}
Would you have some way to do it without having to type all the fields?
The field name in HTML does not match the column name in the database, so you will not be able to make PHP magically know where to store each value, so no, there’s no way to do that. Even if it was, it would not be recommended, because it would be very trusting the data received by the request.
– Woss
But if I use the same name in the fields, it would be possible?
– crishenrique1986
The question is: is there such a need? There are 7 lines of code.
– Woss
The 7 lines were just for example, I have many fields beyond these.
– crishenrique1986
What if a field is not sent together? Or if other fields are sent than expected? What should be the behavior of the application?
– Woss
Your question goes against another question, what I am wanting to do is common, or is done the way I was doing. I would like to know your opinion, even for the security issue, as I questioned earlier.
– crishenrique1986