Oh I am sharing my source in case anyone has this problem with sending out the codes via URL its not perfect solution but it works and is good at picking up data into the SQL if it doesn't work for you don't blame me its provided as is and I have for liability for its use in any capacity.
$servername = "localhost";
$username = "***********";
$password = "*********";
$dbname = "DB NAME";
$filename = "images/nowplaying.txt";
$artwork_filename = "images/nowplaying.txt";
$textXML = "";
$title="";
$artist="";
$album="";
$length="";
$bpm="";
$genre="";
$listeners = "";
$comment = "";
$artwork = "";
function ReturnError($code, $text) {
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
//header($protocol . ' ' . $code . ' ' . $text);
echo "<HTML>";
echo "<img src ='images/favpng_construction-worker-architectural-engineering-cartoon-royalty-free.png' width='200' height='240'></img><br><br>";
echo "SERVER_PROTOCOL ERROR<BR><BR>";
echo "Add data to SQL -.".$text ."<br><br>";
throw Error("EXIT CODE");
exit();
}
// Data Processing
$t = fopen("images/nowplaying_artwork_2.png", 'r');
if ($t !== false)
{
$artwork = fread($t,filesize("images/nowplaying_artwork_2.png"));
fclose($t);
} else {
fclose($t);
ReturnError(500, 'Failed to write artwork to a file.');
}
$base64artwork = base64_encode($artwork);
$r = fopen("images/nowplaying.xml", 'r');
if ($r !== false)
{
$textXML = fread($r,filesize("images/nowplaying.xml"));
fclose($r);
} else {
fclose($r);
ReturnError(500, 'Failed to write artwork to a file.');
}
$artist = substr($textXML,strpos($textXML,"ARTIST=")+8,(strpos($textXML," TITLE=")-strpos($textXML,"ARTIST="))-9);
$title = substr($textXML,strpos($textXML," TITLE=")+8,(strpos($textXML," ALBUM=")-strpos($textXML," TITLE="))-9);
$album = substr($textXML,strpos($textXML," ALBUM=")+8,(strpos($textXML," YEAR=")-strpos($textXML," ALBUM="))-9);
$year = substr($textXML,strpos($textXML," YEAR=")+7,(strpos($textXML," GENRE=")-strpos($textXML," YEAR="))-8);
$genre = substr($textXML,strpos($textXML," GENRE=")+8,(strpos($textXML," COMMENT=")-strpos($textXML," GENRE="))-9);
$comment = substr($textXML,strpos($textXML," COMMENT=")+10,(strpos($textXML,"FILENAME=")-strpos($textXML," COMMENT="))-12);
$length = substr($textXML,strpos($textXML," DURATION=")+12,(strpos($textXML," STARTED=")-strpos($textXML," DURATION="))-13);
$rating = substr($textXML,strpos($textXML," RATING=")+9,(strpos($textXML," BPM=")-strpos($textXML," RATING="))-10);
$bpm = substr($textXML,strpos($textXML," BPM=")+6,(strpos($textXML," TAGS=")-strpos($textXML," BPM="))-7);
$listeners = substr($textXML,strpos($textXML," LISTENERS=")+12,(strpos($textXML," />")-strpos($textXML," LISTENERS="))-13);
$exit_old=false;
// note there is now num_rows in PDO so we have to calculate a new one to get record number.
try {
$n = 0;
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT COUNT(`datetime`) FROM `played_songs` ORDER BY `datetime` ASC";
$result = $conn->query($sql); // Use query as we are returning records.
$row=$result->fetch();
$n = $row["COUNT(`datetime`)"] - 150;
if( $n >1) {
$sql = "SELECT `datetime` FROM `played_songs` ORDER BY `datetime` ASC";
$q = $conn->query($sql);
while ($n) {
$r= $q->fetch();
$id = $r['datetime'] ;
$conn->prepare("DELETE FROM `played_songs` WHERE `datetime`=?")->execute([$id]);
$n--;
}
}
} catch(PDOException $e) {
ReturnError(500, "Failed to write /read from SQL.".$e->getMessage());
}
$conn = null;
try {
$n = 0;
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM `played_songs` ORDER BY `datetime` DESC LIMIT 1";
$result = $conn->query($sql); // Use query as we are returning records.
$row=$result->fetch();
if($artist == $row['artist'] ) {
$con=null;
$exit_old=true;
}
} catch(PDOException $e) {
ReturnError(500, "Failed to write /read from SQL.".$e->getMessage());
}
$conn = null;
// Add record to database.
if($exit_old == false) {
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO `played_songs` (`song`, `artist`, `album`, `length`, `bpm`,`genre`, `listeners`,`track_user_rating`,`track_user_num`,`comment`,`ImageBase64`) VALUES ('$title','$artist', '$album', '$length', '$bpm', '$genre','$listeners','0','0', '$comment','$base64artwork')";
$conn->exec($sql);
//echo "New record created successfully";
} catch(PDOException $e) {
//echo $sql . "<br>" . $e->getMessage();
ReturnError(500, "Failed to write record to SQL.".$e->getMessage());
}
$conn = null;
}
?>