-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetsong.php
66 lines (53 loc) · 1.31 KB
/
getsong.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
<?php
include "server_vars.php";
include "utility.php";
session_start();
$path = "music/";
$mysqli = new mysqli($HOST, $USERNAME, $PASSWORD, $DBNAME_CORE);
if($mysqli->connect_errno)
{
echo "Error connecting to mysql";
}
else
{
echo "MySQL successfully connected";
}
$emotion = $_GET["emotion"];
$counter = ""; //stands for counter emotion
switch($emotion)
{
case "happy":
case "sad": $counter = "happy";
break;
case "angry": $counter = "calm";
break;
case "bored": $counter = "motivational";
break;
default: $counter = "happy";
}
echo "The emotion used here is: " . $emotion . "<br>"; //these statements are for debugging purposes only.
echo "The counter emotion is: " . $counter . "<br>";
$i=0;
if($q1 = $mysqli->prepare("SELECT title, reference FROM musicstore WHERE emotion=?"))
{
$q1->bind_param("s", $counter);
$q1->execute();
$q1->bind_result($title, $reference);
$q1->store_result();
$count = $q1->num_rows;
$limit = rand(1, $count);
while($q1->fetch() && $i < $limit)
{
$_SESSION["song_title"] = $title;
$_SESSION["song_ref"] = $path . $reference;
$i++;
}
}
else
{
echo "MySQL error: " . $mysqli->error;
}
echo "Song about to be played is: " . $_SESSION["song_title"] . "<br>";
echo "Song location: " . $_SESSION["song_ref"] . "<br>";
header("Location: player.php");
?>