我正在尝试列出文本文件中的所有行,并在每一行旁边添加一个删除按钮。当按下该按钮时,该行应被删除。如下所示:
我觉得我很接近解决问题,但无法让它正常工作,有什么想法吗?这些行和按钮显示正常,但删除按钮似乎没有任何作用。
edit.php
Line One Text | Delete
Line Two Text | Delete
Line Three Text | Delete
我觉得我很接近解决问题,但无法让它正常工作,有什么想法吗?这些行和按钮显示正常,但删除按钮似乎没有任何作用。
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!