Question: Assignment: Create a Song Organizer script that stores songs in a text file. Include functionality that allows users to view the song list and prevents

Assignment:

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, deletes duplicate entries, and randomizes the song list with the shuffle() function.

I am having a problem getting my code to create the txt file. Any ideas?

Song Organizer

Song Organizer

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 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 (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 "

The song you entered already exists!
";

echo "Your song was not added to the list.

";

}

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. ";

}

}

if ((!file_exists("SongOrganizer/songs.txt"))

|| (filesize("SongOrganizer/songs.txt") == 0))

echo "

There are no songs in the list.

";

else

{

$SongArray = file("SongOrganizer/songs.txt");

echo "

";

foreach ($SongArray as $Song) {

echo "

";

echo "

";

echo "

";}

echo "

" . htmlentities($Song) . "
";

}

?>

SortSong List

Remove Duplicate Songs

Randomize Song List

Add a New Song

Song Name:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!