Hello! I’m trying to read a list cd names, remove those that have been selected by a user, and return the list to the user. The add function works fine, but remove fails to remove the data selected.
Here’s the snippet:
[php]
Select a Song:
<?php
query1();
?>
Selected songs:
<?php
if(isset($_POST[‘add’])) {
$songsList = fopen(“songsList.txt”, “w”) or die (“Unable to open file!”);
$selected_val = $_POST[‘songList’];
//$value = mysqli_fetch_row($selected_val);
foreach ($selected_val as $sVal) {
//echo $selectedOption."\n";
echo ‘’.$sVal.’’;
fwrite($songsList, $sVal."\r\n");
}
fclose();
}
if(isset($_POST[‘remove’])) {
$songsList = fopen(“songsList.txt”, “r+”) or die (“Unable to open file!”);
$selected_val = $_POST[‘songList’];
$songsList = array_diff($songsList, $selected_val);
foreach($songsList as $key => $song) {
fwrite($songsList, $song."\r\n");
echo ‘’.$song.’’;
}
fclose();
}
?>[/php]