-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-movie.php
83 lines (71 loc) · 2.94 KB
/
add-movie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// Include config file
require_once 'config.php';
// Initialize the session
session_start();
// If session variable is not set it will redirect to login page
if (!isset($_SESSION['role']) || empty($_SESSION['role'])) {
header("location: /");
exit;
}
// If session variable is not set it will redirect to login page
if (!isset($_SESSION['email']) || empty($_SESSION['email'])) {
header("location: /");
exit;
}
// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Prepare an insert statement
$sql = "INSERT INTO movie
(poster_url, title, duration_minutes, age_rating, plot, start_date, movie_supplier_id, end_date)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?)";
if ($stmt = mysqli_prepare($link, $sql)) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ssssssss", $param_poster_url, $param_title, $param_duration_minutes, $param_age_rating, $param_plot, $param_start_date, $param_movie_supplier_id, $param_end_date);
// Set parameters
$param_poster_url = trim($_POST['poster_url']);
$param_title = trim($_POST['title']);
$param_duration_minutes = trim($_POST['duration_minutes']);
$param_age_rating = trim($_POST['age_rating']);
$param_plot = trim($_POST['plot']);
$param_start_date = trim($_POST['start_date']);
$param_movie_supplier_id = trim($_POST['movie_supplier_id']);
$param_end_date = trim($_POST['end_date']);
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
$last_id = mysqli_insert_id($link);
foreach ($_POST['actor_ids'] as $actor_id) {
$sql_plays = "INSERT INTO plays
(actor_id, movie_id)
VALUES
($actor_id, $last_id)";
if (!mysqli_query($link, $sql_plays)) {
echo "Something went wrong. Please try again later.";
}
}
$director_id = trim($_POST['director_id']);
$sql_directs = "INSERT INTO directs
(director_id, movie_id)
VALUES
($director_id, $last_id)";
if (!mysqli_query($link, $sql_directs)) {
echo "Something went wrong. Please try again later.";
}
$production_company_id = trim($_POST['production_company_id']);
$sql_production_company = "INSERT INTO makes
(production_company_id, movie_id)
VALUES
($production_company_id, $last_id)";
if (!mysqli_query($link, $sql_production_company)) {
echo "Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
// Redirect to login page
header("location: /dashboard");
} else {
echo "Something went wrong. Please try again later.";
}
}
}