My objective is to try that if an item of my first table has the foreign key that would be a GENRE, it does not let me delete that GENRE in my second table, for this I do a SQL query but it keeps throwing me the error that I cannot delete my foreign key, does anyone have an idea that I could be wrong? Here I am going to leave my SQL query and my delete function to eliminate it. If the gender is not being used in the other table it lets me delete it normally...
Clarification: I have the tables linked by Genero_ID
Esta funcion es un contador en la base de datos a ver si algún genero esta siendo utilizado.
function contadorCategoria($Genero_ID){
$sentencia = $this->db->prepare("SELECT count(*) FROM generos c JOIN juegos l ON c.Genero_ID = l.Genero_ID LIKE ? GROUP BY c.Genero");
$sentencia->execute(array($Genero_ID));
$contador = $sentencia->fetchAll(PDO::FETCH_OBJ);
return $contador;
}
Funcion que hace el delete segun si el contador esta null o no...
function deleteGEN($Genero_ID){
$this->userHelper->checkLoggedIn();
$contador = $this->modelGenero->contadorCategoria($Genero_ID);
if ($contador == NULL){
$this->modelGenero->DeleteGeneroByIDGen($Genero_ID);
header("Location: " . BASE_URL);}
else {header("Location: " . BASE_URL);}}
My boards are called games and genres.