function inputValues($mName, $mYear, $actFirstName, $actLastName, $dirFirstName, $dirLastName, $db) { if ($mName == null || $mYear == null) { print "Please complete mandotory fields: movie name, year and genre."; return FALSE; } else { # use inputs actFirstName or actLastName or both if ($actFirstName != "" || $actLastName != "") { $actorID = fetchActorsID($actFirstName, $actLastName, $db); #actor isn't in database if ($actorID == -1) { exit(0); } } // use inputs dirFirstName or dirFirstName or both if ($dirFirstName != "" || $dirLastName != "") { $director_id = fetchDirectorsID($dirFirstName, $dirLastName, $db); // director not in the db if ($director_id == -1) { exit(0); } } return TRUE; } //end of movie inputs }
$stmt->bindParam(":id", $newMovieID); $stmt->bindParam(":mName", $mName); $stmt->bindParam(":mYear", $mYear); $stmt->execute(); # updating table movies_directors if ($dirFirstName != "" && $dirFirstName != "") { $director_id = fetchDirectorsID($dirFirstName, $dirLastName, $db); $stmt = $db->prepare("INSERT INTO movies_directors (director_id, movie_id) VALUES (:director_id, :movieID)"); $stmt->bindParam(":director_id", $director_id); $stmt->bindParam(":movieID", $newMovieID); $stmt->execute(); } # updating table role if ($actFirstName != "" && $actLastName != "") { // $actorID is not -1 $actorID = fetchActorsID($actFirstName, $actLastName, $db); $stmt = $db->prepare("INSERT INTO roles (actor_id, movie_id) VALUES (:actorID, :movieID)"); $stmt->bindParam(":actorID", $actorID); $stmt->bindParam(":movieID", $newMovieID); $stmt->execute(); # updating actor role's film_count column $stmt = $db->prepare("UPDATE actors SET film_count=film_count +1 WHERE id = :actorID"); $stmt->bindParam(":actorID", $actorID); $stmt->execute(); } } catch (PDOException $e) { die("Error: {$e->getMessage()}"); } print $mName . ", " . $mYear . " added successfully into imdb_small database."; } }