0
我只是試圖輸出一些表單數據到文本文件。我無法讓它工作。有人能幫忙嗎?我收到錯誤invalid offset type
。感謝所有的幫助!輸出表單數據到PHP中的文件
這裏是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>
@KristerAnderson我仍然得到警告說,提供的foreach'無效的參數()'它發佈到文件中。有沒有什麼方法可以格式化輸出,使它看起來更好? – zachstarnes
@zachstarnes - 如果您仍然收到「無效的偏移量」警告,那麼我認爲您還在做其他事情。只要您的數據確實發佈到網頁上,上述內容就會有效。 – Cyclonecode
@kristenanderson我不再收到這個警告。我得到一個新的說'爲foreach()'提供的無效參數和數據會發布到頁面:) – zachstarnes