diff --git a/panel_admin/includes/film_dao.php b/panel_admin/includes/film_dao.php index aaa6d3a..3f34771 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 a film data . + 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. diff --git a/panel_admin/includes/formFilm.php b/panel_admin/includes/formFilm.php index e3d89c7..773ad21 100644 --- a/panel_admin/includes/formFilm.php +++ b/panel_admin/includes/formFilm.php @@ -46,28 +46,48 @@ class FormFilm extends Form { } //Process form: - public function processesForm($id,$title,$duration,$languaje,$description, $option) { - $this->correct = true; + public function processesForm($id,$tittle,$duration,$language,$description, $option) { + $this->correct = true; $this->option = $option; - + //Habria que validar todo para que encaje en la base de datos - + $bd = new Film_DAO('complucine'); 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); + //Primero comprobar si existe una pelicula con el mismo 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); + //Primero comprobar si existe una pelicula con el mismo id + $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(); } - } else {$this->correct = false;} - - } - + } else {$this->correct = false;} + } + + } } ?> \ No newline at end of file