我正在尝试列出文本文件中的所有行,并在每一行旁边都有一个删除按钮。按下按钮时,应删除该行。像下面
Line One Text | Delete
Line Two Text | Delete
Line Three Text | Delete
我想我很接近但无法让它工作,有什么想法吗?线条和按钮显示正常,但删除按钮似乎没有做任何事情。
编辑.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;
?>
删除器.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;
?>
提前致谢!