我只是想将一些表单数据输出到文本文件。我无法让它工作。有人能帮忙吗?我得到一个错误invalid offset type
。感谢所有的帮助!
这是php
$file = "output.txt";
$current = file_get_contents($file);
foreach ($_POST as $key) {
$current .= $_POST["data"][$key];
}
file_put_contents($file, $current);
这是html
<form name="input" action="getinput.php" method="post">
Name: <br /><input type="text" name="data[]" placeholder="First and Last"><br />
ID: <br /><input type="text" name="data[]" placeholder="Your ID"><br />
Major: <br /><input type="text" name="data[]" placeholder="Your Major"><br />
Email: <br /><input type="email" name="data[]" placeholder="Email Address"><br />
Phone: <br /><input type="text" name="data[]" placeholder="XXX-XXX-XXXX"><br />
Addition Information: <br /><textarea name="data[]" cols="30" rows="10" placeholder="Please enter any extra or comments you would like me to have or know."></textarea><br />
<input type="submit" value="Submit">
</form>