-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddToDB.php
86 lines (77 loc) · 3.85 KB
/
addToDB.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
84
85
86
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/cover.css" rel="stylesheet">
<?php
require_once 'config.php';
?>
<html>
<body class="d-flex h-100 text-center text-white bg-dark">
<div class="container">
<main class="px-3 row">
<h1>Add video to game set:</h1>
<form action="addToDB.php" method="post">
<div class="row mb-3">
<label for="setId">Set</label>
<select id="setId" name="set" class="form-control">
<?php
$sql = "SELECT * FROM sets ORDER BY SetID";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<option value="'.$row["SetID"].'">'.$row["SetDescription"].'</option>';
}
} else {
//Fallback, if database throughts an error
echo '<option value="0">Random songs from all categories</option>';
}
?>
</select>
</div>
<div class="row mb-3">
<label for="youtubeID" class="form-label">Youtube-ID / Video link</label>
<input type="text" class="form-control" name="youtubeID" id="youtubeID" placeholder="dQw4w9WgXcQ">
</div>
<div class="row mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" name="password" id="password" placeholder="hunter2">
</div>
<div class="row mb-3">
<button type="submit" class="btn btn-primary mb-3">Add to gameset</button>
</div>
<div class="row mb-3">
<a href="index.php">Home</a>
</div>
</form>
</main>
<div class="px-3 row">
<?php
if(isset($_POST["youtubeID"])){
if($_POST["password"] == $addToDBPass){
$youtubeID = $_POST["youtubeID"];
//Remove everything before =
if(strpos($youtubeID, "=")){
$youtubeID = strstr($youtubeID, '=');
$youtubeID = substr($youtubeID, 1);
}
//Remove everything after &
if(strpos($youtubeID, "&")){
$youtubeID = substr($youtubeID, 0, strpos($youtubeID, "&"));
}
//Insert into db
$sql = "INSERT INTO songs (SongLink, SetID) VALUES ('" . $youtubeID . "', '" . $_POST["set"] . "')";
if ($conn->query($sql) === TRUE) {
echo "Added to database successfully!";
} else {
echo "ERROR: " . $sql . "<br>" . $conn->error;
}
}
else{
echo "ERROR: Wrong password!";
}
}
$conn->close();
?>
</div>
</div>
</body>
</html>