Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am getting an errors! I need the the answer in PHP format. Create a Song Organ

ID: 3531468 • Letter: I

Question

I am getting an errors! I need the the answer in PHP format.

Create a Song Organizer script that stores songs in a text file. Include functionality that allows users to view the song list and prevents the same song name from being entered twice. Also, include code that sorts the songs by name,delete duplicate entries, and radomizes the song list with the shuffle() function. Here is the code that I am getting a error: List below:

<!DOCTYPE html>
<html>
<head>
<title>Song Organizer</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Song Organizer</h1>
<?php
if (isset($_GET['action'])) {
if ((file_exists("SongOrganizer/songs.txt"))
&& (filesize("SongOrganizer/songs.txt")
!=0)) {
$SongArray = file("SongOrganizer/songs.txt");


switch ($_GET['action']) {
case 'Remove Duplicates':
$SongArray = array_unique($SongArray);
$SongArray = array_values($SongArray);
break;
case 'Sort Ascending':
sort($SongArray);
break;
case 'Shuffle':
shuffle($SongArray);
break;
} // End of the switch statement

if (count($SongArray)>0) {
$NewSongs= implode($SongArray);
$SongStore = fopen("SongOrganizer/songs.txt" , "wb");
if($SongStore === false)
echo "There was an error updating the song file ";
else {
fwrite($SongStore, $NewSongs);
fclose($SongStore);
}
}
else
unlink("SongOrganizer/songs.txt");
}
}

if ((!file_exists("SongOrganizer/songs.txt"))
|| (filesize("SongOrganizer/songs.txt")
==0))
echo "<p>There are no songs in the list.</p> ";
else{
$SongArray = file("SongOrganizer/songs.txt");
echo "<table border="1" width="100%"
> ";
foreach ($SongArray as $Song) {
echo "<tr> ";
echo "<td>" . htmlentities($Song) .
"</td>";
echo "</tr> ";
}
echo "</table> ";
}

if (isset($_POST['submit'])) {
$SongToAdd = stripslashes($_POST['SongName']) . " ";
$ExistingSongs = array();
if (file_exists("SongOrganizer/songs.txt")
&& filesize("SongOrganizer/songs.txt")
> 0) {
$ExistingSongs = file("SongOrganizer/songs.txt");
}
}

if (in_array($SongToAdd, $ExistingSongs)) {
echo "<p>The song you entered already exists!<br /> ";
echo "Your song was not added to the list.</p>";
}

else{
$SongFile = fopen("SongOrganizer/songs.txt", "ab");
if ($SongFile ===false)
echo "There was an error saving your message! ";
else{
fwrite($SongFile, $SongToAdd);
fclose($SongFile);
echo "Your song has been added to the list. ";
}
}

?>
<p>
<a href="SongOrganizer.php?action=Sort Ascending">
Sort Song List</a><br />
<a href="SongOrganizer.php?action=Remove Duplicates">
Remove Duplicate Songs</a><br />
<a href="SongOrganizer.php?action=Shuffle">
Randomize Song list</a><br />
</p>

<form action="SongOrganizer.php" method="post">
<p>Add a New Song</p>
<p>Song Name: <input type="text" name="SongName"/></p>
<p><input type="submit" name="submit" value="Add Song to List" />
<input type ="reset" name="reset" value="Reset Song Name" /></p>
</form>

</body>
</html>


Explanation / Answer

The following code will automatically launch background music and will play through the song file only once. It will also embed a player into the page so that the visitor can stop the music if they want to.

<embed src="yourfile.mid" autostart="true" width="130" height="40"> </embed> <noembed> <bgsound src="yourfile.mid"> </noembed>

Important elements of this code to make not of include the "noembed" tag, which allows you to make the page compatible with all browsers. Secondly, you can modify the size of the player using the "width" and "height" properties so that it fits well within your page.

The code below will automatically launch background music and will play through the song file in a continuous loop. It will also embed a player into the page so that the visitor can stop the music if they want to. Keep in mind that many website visitors find continuous background music very annoying, so use this code as tactfully as possible.

<embed src="yourfile.mid" autostart="true" loop="true" width="130" height="40"> </embed> <noembed> <bgsound src="yourfile.mid" loop="infinite"> </noembed>

One of the most common methods used to play background music on a web page is the hidden technique. Using the code below, the music will launch automatically in the background, and no player will appear on the screen. Keep in mind that this means the visitor will not be able to turn the music off, so it's best to play the file once, and not continuous.

<embed src="yourfile.mid" hidden="true" autostart="true"> </embed> <noembed> <bgsound src="yourfile.mid"> </noembed>