Hey guys, I'm trying to output the contents of a text file onto the body of the page after a button click. After that, I want to write to the text file with a form and then output the contents once again. I think I'm almost there, but the code isn't working. Can you point out what I'm doing incorrectly? Thanks.
<?php
echo "<u><b>Song List</b></u><br />";
$list = "songList.txt";
//song list
$data = "Imagine"."<br />"."Born to Run"."<br />"."Ain't No Sunshine"."<br />"."Hey Jude"."<br />"."Hotel California"."<br />"."Layla"."<br />"."Stairway to Heaven"."<br />"."What's Going On"."<br />"."Yesterday"."<br />"."Heartbreak Hotel"."<br />";
//fopen to open file, 2nd argument 'w' to write
$open = fopen($list, 'w');
fwrite($open, $data);
fclose($open);
//return $list;
//on clicking view button
if (isset($_POST['view'])) {
$output_view = file_get_contents($list);
echo $output_view; }
//appending new songs
if (isset($_POST['newSong']) && isset($_POST['submit'])){
$append = fopen($list, 'a');
$newdata = $_POST['newSong'];
fwrite($append, $newdata);
fclose($append);
readfile($list);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<body>
----------------------------------------
<form action="" method="POST">
<input type="button" name="view" value="View List">
<input type="button" name="sort" value="Sort List">
<input type="button" name="shuffle" value="Shuffle List"><br /><br />
<input type="text" name="newSong" value="Insert Song Title">
<input type="button" name="submit" value="Add Song">
</form>
</body>
</html>