我正在尝试通过PHP脚本将日志从HTML表单保存到文本文件,但是似乎什么也没发生。单击“提交”按钮后,我被重定向到脚本的空白页面,但我也希望到达另一个页面“ list.html”。
我的索引文件:
<!DOCTYPE html>
<html>
<head>
<title>Welcome1</title>
</head>
<body>
<form action="process.php" method="POST">
Name: <input type="text" name="username">
Surname: <input type="text" name="surname">
<input type="submit" value="Open">
</form>
</body>
</html>
在同一文件夹中,我有以下php脚本:
<?php
$name=$_POST['username'];
$surname=$_POST['surname'];
$handle = fopen("names.txt", "a");
fwrite($handle, "name: ");
fwrite($handle, $username);
fwrite($handle, "\n");
fwrite($handle, "surname: ");
fwrite($handle, $surname);
fwrite($handle, "\n");
fwrite($handle, "\n");
fclose($handle);
header('location:list.html');
?>