I need to display and save data in my database but as I'll show below I'm using Joins to display, for example the name of an author using their primary key. For display is working, but when I use my method to insert data into the table it returns an error with the foreign key, so I could understand my code is trying to insert the returned name as if it were the foreign key as this key will not go there is error, below code and images of what I'm doing:
My screen where the author's name is displayed:
Mycodeusedtoreturntheabovescreendata:
functionhistory($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();}
Mycodetoinsertthedataintothedatabase:
functioninserir_coment($data){return$this->db->insert('comentarios',$data,"autor.comentarios = user.id");
}
Error returned while executing this code:
I think that by typing the syntax to insert the data my problem is solved, but as I am beginner I could not solve it myself, for this application I am using Codeigniter 3.1.3.