-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertPlaylist.php
45 lines (38 loc) · 1000 Bytes
/
insertPlaylist.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
<html>
<head></head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
function insert($pid, $trackId) {
global $servername, $username, $password;
$mysqli = new mysqli($servername, $username, $password, "dbproject");
if (mysqli_connect_errno()) {
die("Connect to db failed: " . "<br>" . mysqli_connect_error() );
}
$positio = "SELECT position from Playlist where pid = $pid Order by position desc limit 1";
$st = $mysqli->prepare($positio);
$st->execute();
$st->bind_result($poss);
$valid = $st->fetch();
$st->close();
$poss++;
$sql = "INSERT INTO Playlist (pid, trackID, position) VALUES (?, ?, ?)";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('iii', $pid, $trackId, $poss);
$stmt->execute();
$valid = $stmt->fetch();
$stmt->close();
$mysqli->close();
}
?>
<?php
session_start();
$pid = $_POST['pid'];
$trackId = $_POST['trackId'];
$name = $_SESSION['login_user'];
insert($pid, $trackId);
?>
</body>
</html>