-
Notifications
You must be signed in to change notification settings - Fork 2
/
WYDRN.php
166 lines (133 loc) · 6.34 KB
/
WYDRN.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
*- STANDARDIZES USER INPUT IN PROPER FORMAT AND INSERTS INTO THE DATABASE. IF ALL FIELDS ARE EMPTY, INSERTS NOTHING AND DISPLAYS APPROPRIATE MESSAGE ON THE PROFILE CARD
* - IF AT LEAST ONE OF THE FIELDS IS NOT EMPTY, INSERTS INTO THE DATABASE.
* - DISPLAYS THE LATEST DATA FROM THE DATABASE ON THE PROFILE PAGE.
* - THIS IS THE MAIN DEPENDENCY OF PROFILE.PHP
* @version PHP 8.0.12
* @since June 2022
* @author AtharvaShah
*/
echo '
<style type="text/css">
div{
font-size: 14px;
}
</style>
';
require("connection.php");
$user_data = check_login($con);
//$username=$user_data['user_name'];
if (isset($_GET['user_name'])){
$username=$_GET['user_name'];
}else{
$username=$user_data['user_name'];
}
//global variables initializing to ''
$videogame='';
$platform='';
$album='';
$artist='';
$book='';
$author='';
$movie='';
$movierelease='';
$TV='';
$streamplatform='';
//video game validation
if ((!empty($_POST['Videogame'])) && (!empty($_POST['Platform']))){
global $videogame, $platform;
$videogame=mysqli_real_escape_string($con, $_POST['Videogame']);
$platform=mysqli_real_escape_string($con, $_POST['Platform']);
}
//music validation
if ((!empty($_POST['Album'])) && (!empty($_POST['Artist']))){
global $album, $artist;
$album=mysqli_real_escape_string($con, $_POST['Album']);
$artist=mysqli_real_escape_string($con, $_POST['Artist']);
}
//book validation
if ((!empty($_POST['Book'])) && (!empty($_POST['Author']))){
global $book, $author;
$book=mysqli_real_escape_string($con, $_POST['Book']);
$book=trim($book,".");
$author=mysqli_real_escape_string($con, $_POST['Author']);
}
//movie validation
if ((!empty($_POST['Movie'])) && (!empty($_POST['MovieRelease']))){
global $movie, $movierelease;
$movie=mysqli_real_escape_string($con, $_POST['Movie']);
$movierelease=mysqli_real_escape_string($con, $_POST['MovieRelease']);
}
//tv validation
if ((!empty($_POST['TV'])) && (!empty($_POST['StreamPlatform']))){
global $TV, $streamplatform;
$TV=mysqli_real_escape_string($con,$_POST['TV']);
$streamplatform=mysqli_real_escape_string($con,$_POST['StreamPlatform']);
}
// insert the fields into the database if at least one of the above fields is filled.
if ((!empty($videogame)) || (!empty($album)) || (!empty($book)) || (!empty($movie)) || (!empty($TV)))
{
$sql="INSERT INTO `data`(`username`, `videogame`, `platform`, `album`, `artist`, `book`, `author`, `movie`, `year`, `tv`, `streaming`)
VALUES ('$username', '$videogame', '$platform', '$album', '$artist', '$book', '$author', '$movie', '$movierelease', '$TV', '$streamplatform')";
$result=mysqli_query($con,$sql);
// Check if insert statement was successful and display the relevant message
//uncomment the echo statements when debugging
if($result){
//echo "The record has been inserted successfully successfully!<br>";
}
else{
//echo "Record not inserted. ERROR -> ". mysqli_error($con);
}
}
//select the data corresponding to the user (tail 1)
$sql="SELECT * FROM `data` WHERE `username` = '$username' ORDER BY `datetime` DESC LIMIT 1";
if ($result=mysqli_query($con, $sql)){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
//uncomment when debugging
//print_r($row);
//set the data
$videogame=$row['videogame'];
$platform=$row['platform'];
$album=$row['album'];
$artist=$row['artist'];
$book=$row['book'];
$author=$row['author'];
$movie=$row['movie'];
$movierelease=$row['year'];
$TV=$row['tv'];
$streamplatform=$row['streaming'];
//display the data [UNCOMMENT THE ELSE AND THE LINE BELOW IT FOR ALL 5 SECTIONS TO HIDE THE NOT PLAYING MESSAGES. EASY FIX.]
if ((!empty($videogame)) && (!empty($platform)))
$playing="<div class='media-item' id='media-game'>🎮 Playing <b>".$videogame."</b> on ".$platform."</div>";
// else
// $playing="<div class='media-item'>🎮 NOT PLAYING ANYTHING ❌</div>";
if ((!empty($album)) && (!empty($artist)))
$listening="<div class='media-item' id='media-music'>🎧 Listening to <b>".$album."</b> by ".$artist."</div>";
// else
// $listening="<div class='media-item'>🎧 NOT LISTENING TO ANYTHING ❌</div>";
if ((!empty($book)) && (!empty($author)))
$reading="<div class='media-item' id='media-book'>📕 Reading <b>".$book."</b> by ".$author."</div>";
// else
// $reading="<div class='media-item'>📕 NOT READING ANYTHING ❌</div>";
if ((!empty($movie)) && (!empty($movierelease)))
$watching="<div class='media-item' id='media-movie'>📽 Watching <b>".$movie."</b> (".$movierelease.")</div>";
// else
// $watching="<div class='media-item'>📽 NOT WATCHING ANYTHING ❌</div>";
if ((!empty($TV)) && (!empty($streamplatform)))
$binging="<div class='media-item' id='media-tv'> 📺 Binging <b>".$TV."</b> on ".$streamplatform."</div>";
// else
// $binging="<div class='media-item'>📺 NOT BINGING ANYTHING ❌</div>";
}
}
}
if ((empty($playing))&& (empty($listening))&& (empty($reading))&& (empty($watching))&& (empty($binging)))
echo "<div> 😞 Nothing to see here.</div>";
//this is stuff used to display the text on the browser. This will be eventually replaced by SQL queries.
if (!empty($playing)) echo $playing."<BR>";
if (!empty($listening)) echo $listening."<BR>";
if (!empty($reading)) echo $reading."<BR>";
if (!empty($watching)) echo $watching."<BR>";
if (!empty($binging)) echo $binging."<BR>";
?>