I have this php file that allows a user to enter their favorite music artist. My program puts the entered artist in a variable called "art" and then adds it to an array called "artist". Then it displays the array in a bullet list. But the program as it is only allows one value to be in the array. When the user enters another artist, it overwrites the one that is already in the array. For example, the user writes "bob" as their favorite artist and presses submit. The program displays bob, but when you go to put in another artist, "tess", bob is gone and only tess is diplayed. How do i fix this?
Here is the code: (Don't mind the commented out echo, it was a test to see if the entered value was being assigned to the variable.)
<h1> My Favorite Artist </h1>
<form method='POST'>
<h3>Please enter your favorite artist</h3>
<input type="text" name="artist">
<input type="submit" value="Submit Artist">
</form>
<?php
$art = $_POST['artist'];
//echo "<h3> This $art </h3>";
$artist = array();
array_push($artist, $art);
foreach ($artist as $a)
{
echo "<li>$a</li>";
}
?>
$artistarray between requests. Using session storage seems a good fit