-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectPlaylist.php
92 lines (66 loc) · 2.04 KB
/
selectPlaylist.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
87
88
89
90
91
92
<doctype! html>
<html>
<head>
<title> Select Playlist </title>
<h1> Add to Playlist: </h1>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/mgalante/jquery.redirect/master/jquery.redirect.js"></script>
<script>
function insert(pid,trackId) {
$.post('insertPlaylist.php', {'pid':pid, 'trackId':trackId});
alert("Track Added to Playlist");
}
function createNew(trackId) {
var pname = $("#inputName").val();
$.post('createPlaylist.php', {'trackId':trackId, 'pname':pname});
alert("New Playlist Created");
}
</script>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
function display($name, $id) {
global $servername, $username, $password;
$mysqli = new mysqli($servername, $username, $password, "dbproject");
if (mysqli_connect_errno()) {
die("Connect to db failed: " . "<br>" . mysqli_connect_error() );
}
$statement = "SELECT pid, ptitle FROM PlaylistInfo WHERE username = '{$name}'";
$stmt = $mysqli->prepare($statement);
$stmt->execute();
$stmt->bind_result($pid, $title);
$valid = $stmt->fetch();
echo "<table border=\"1\">";
if (!$valid) {
echo "No Results Found";
}
while ($valid) {
echo "<tr>";
echo "<td>";
echo $title . " ";
echo "<button onclick=\"insert('$pid', '$id')\"> Add </button>";
echo "</td>";
echo "</tr>";
$valid = $stmt->fetch();
}
echo "</table>";
$stmt->close();
$mysqli->close();
echo "<br><input id = \"inputName\" type=\"text\" name=\"createNew\" placeholder=\"Insert Name..\"><br>";
echo "<button id=\"newPlay\" onclick=\"createNew('$id')\">Create New Playlist</button>";
echo "<br><br><form action=\"welcome.php\" method=\"post\">";
echo "<input type=\"submit\" class=\"button\" value=\"Home\">";
echo "</form>";
}
?>
<?php
session_start();
$name = $_SESSION['login_user'];
$id = $_POST['id'];
display($name, $id);
?>
</body>
</html>