diff --git a/panel_admin/includes/film_dao.php b/panel_admin/includes/film_dao.php index aaa6d3a..605f448 100644 --- a/panel_admin/includes/film_dao.php +++ b/panel_admin/includes/film_dao.php @@ -18,7 +18,13 @@ $id, $tittle, $duration, $language,$description); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); - return $sql; + return $resul; + } + //Returns + public function GetFilm($tittle,$language){ + $sql = sprintf( "SELECT * FROM film WHERE film.tittle = '%s'AND film.language='%s'", $tittle,$language ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + return $resul; } //Returns a query to get the film's data. @@ -28,6 +34,8 @@ return $resul; } + + //Returns a query to get All the films. public function allFilmData(){ diff --git a/panel_admin/includes/formFilm.php b/panel_admin/includes/formFilm.php index e3d89c7..23e3979 100644 --- a/panel_admin/includes/formFilm.php +++ b/panel_admin/includes/formFilm.php @@ -46,7 +46,7 @@ class FormFilm extends Form { } //Process form: - public function processesForm($id,$title,$duration,$languaje,$description, $option) { + public function processesForm($id,$tittle,$duration,$language,$description, $option) { $this->correct = true; $this->option = $option; @@ -56,11 +56,29 @@ class FormFilm extends Form { if($bd ){ if($option == "new"){ //Primero comprobar si existe una pelicula con el mismo titulo e idioma - $bd->createFilm(null, $title,$duration,$languaje,$description); + $exist = $bd-> GetFilm($tittle,$language); + if( mysqli_num_rows($exist) != 0){ + $this->correct =false; + } + else{ + $bd->createFilm(null, $tittle,$duration,$language,$description); + } } else if ($option == "del"){ - $bd->deleteFilm($id); + $exist = $bd-> FilmData($id); + if( mysqli_num_rows($exist) != 0){ + $bd->deleteFilm($id); + } + else{ + $this->correct =false; + } } else if ($option == "edit"){ - $bd->editFilm($id,$title,$duration,$languaje,$description); + $exist = $bd-> FilmData($id); + if( mysqli_num_rows($exist) != 0){ + $bd->editFilm($id,$tittle,$duration,$language,$description); + } + else{ + $this->correct =false; + } } else if($this->option == "show") { $this->array = $bd->allFilmData(); }