i am trying to list all of the lines in a text file and have a delete button next to each one. When the button is pressed that line should be deleted. like below
Line One Text | Delete Line Two Text | Delete Line Three Text | Delete
I think i am quite close but cannot get it to work, any ideas why? The lines and buttons display fine, but the delete button does not seem to do anything.
edit.php
<?php$textFile = file("guestbook.txt");foreach ($textFile as $key => $val) { $line = @$line . $val . "<input type='submit' name=$key value='Delete'><br />";}$form = "<form name='form' method='post' action='deleter.php'> $line </form>";echo $form;?>
deleter.php
if ($delete != ""&& $delete > !$lines || $delete === '0') { $textFile[$delete] = ""; $fileUpdate = fopen("data.txt", "wb"); for ($a = 0; $a < $lines; $a++) { fwrite($fileUpdate, $textFile[$a]); } fclose($fileUpdate); header("Location:edit.php"); exit;}foreach ($textFile as $key => $val) { $line = @$line . $val . "<a href =?delete=$key> Delete </a><br />";}echo $line;?>
Thanks in advance!