showing up from .txt file and actions not working correctly

I am having a problem with  showing up in my first table box as well as my three actions are not working correctly… I Have been trying to find something within the code to fix this but without any luck. Hope you guys can help me!
Here is my Code:
[php]

Song Organizer

Song Organizer

<?php if (isset($_GET['action'])) { if ((file_exists("SongOrganizer/songs.txt")) && (filesize("SongOrganizer/song.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 Statment 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\n"; else { fwrite($SongStore, $NewSongs); fclose($SongStore); } } else unlink("SongOrganizer/songs.txt"); } } if(isset($_POST['submit'])) { $SongToAdd = stripslashes($_POST['SongName']) . "\n"; $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!
\n"; 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!\n"; else { fwrite($SongFile, $SongToAdd); fclose($SongFile); echo "Your song has been added to the list.\n"; } }
	}

if ((!file_exists(“SongOrganizer/songs.txt”)) || (filesize(“SongOrganizer/songs.txt”) == 0))
echo “

There are no songs in the list.

\n”;
else
{
$SongArray = file(“SongOrganizer/songs.txt”);
echo “<table border=“1” width=“100%” style=“background-color:lightgray”>\n”;
foreach ($SongArray as $Song)
{
echo “\n”;
echo “” . htmlentities($Song) . “”;
echo “\n”;
}
echo “\n”;
}
?>

Sort Song List
Remove Duplicate Songs
Randomize Song list

Add a New Song

Song Name:

[/php]

Well, I think your if-else’s are messed up… (At least with the spacing formats you are showing!)

This:
if($SongStore === false)
echo “There was an error updating the song file\n”;
else
{
fwrite($SongStore, $NewSongs);
fclose($SongStore);
}
Executes ONE line then goes nowhere… If() blah…; It should be something like:
if($SongStore === false) {
echo “There was an error updating the song file\n”;
} else {
fwrite($SongStore, $NewSongs);
fclose($SongStore);
}
So that it is an IF-do something-Else-do something else…

I would check your IF clause logic and see if that clears it up…

Oh, also, using the IF with “===” means IDENTICAL. So, $SongStore === false may not be true as the “false” is a boolean value and the $SongStore would have to be declared as a boolean variable. If created as a “handle” from “fopen()” then, it is not actually a boolean. Usually, you want to check for “==” which is EQUAL. Using IDENTICAL means if(5===“5”) is false. So, not sure if that is what you wanted to use! This is the format they suggest to use for checking “handles” for file opens:
if(!file_exists(“filename.txt”)) {
die(“File not found”);
} else {
$file=fopen(“filename.txt”,“r”);
}
Just FYI…

Sponsor our Newsletter | Privacy Policy | Terms of Service