-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_show.php
More file actions
64 lines (48 loc) · 1.47 KB
/
Copy pathupdate_show.php
File metadata and controls
64 lines (48 loc) · 1.47 KB
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
<?php
$show_id = $_POST["id"];
$mode = $_POST["mode"];
if ($show_id == "") {
die("An error ocurred: No show id provided");
}
$config = include('config.php');
$server = $config["server"];
$db_name = "tracker";
$username = "tracker";
$password = $config["db_pass"];
$conn = mysqli_connect($server, $username, $password, $db_name);
if (!$conn) {
die("Error: " . mysqli_connect_error());
}
if ($mode == "delete") {
$query = "DELETE FROM shows WHERE id={$show_id}";
if (mysqli_query($conn, $query)) {
header("Location: index.php");
die();
} else {
die("Error.");
}
}
$get_current = "SELECT current_episode,current_season,seasons,episodes FROM shows WHERE id={$show_id}";
$result = mysqli_query($conn, $get_current);
if (mysqli_num_rows($result) <= 0) {
die("Error. No shows with that id found");
}
$row = mysqli_fetch_assoc($result);
$current_episode = $row["current_episode"];
$current_season = $row["current_season"];
$seasons = $row["seasons"];
$episodes = $row["episodes"];
$updated_episode = $current_episode + 1;
$updated_season = $current_season;
if ($updated_episode > $episodes) {
$updated_episode = 1;
$updated_season += 1;
}
$query = "UPDATE shows SET current_episode={$updated_episode}, current_season={$updated_season} WHERE id={$show_id}";
if(mysqli_query($conn, $query)) {
header("Location: index.php");
} else {
echo "Error. ";
}
mysqli_close($conn);
?>