0
Say guys all right, I’m having the following doubt:
I need to view and save data in my database but as I will show below I am using Joins to display, for example the name of an author using his primary key. To display this working, but when I use my method to insert data in the table it returns an error with the foreign key, by what I could understand my code is trying to insert the returned name as if it were the foreign key as this key will not exist it of error, below code and images of what I am doing:
My screen from where the author’s name is displayed:
My code used to return the data from the above screen:
function history($ccod) {
$this->db->select('dat, cliente, texto, comcod, cnome, username');
$this->db->where('cliente', $ccod);
$this->db->from('comentarios');
$this->db->join('clientes', 'clientes.ccod = comentarios.cliente');
$this->db->join('users', 'users.id = comentarios.autor');
$query = $this->db->get();
return $query->result();
}
My code to enter the data in the database:
function inserir_coment($data) {
return $this->db->insert('comentarios', $data, "autor.comentarios = user.id");
}
Error returned when executing this code:
I believe that arranging the syntax to enter the data my problem is solved, but as I am beginner I could not solve alone, for this application I am using Codeigniter 3.1.3.
What does it mean
autor.comentarios = user.id
?– rray