我看到了this question,我想在評論中提問,但沒有足夠的聲望。所以我在這裏問這個問題。用PHP中的表單寫入.txt文件
我在HTML表單:
<form action="myprocessingscript.php" method="POST">
Name : <input name="field1" type="text" />
Email : <input name="field2" type="text" />
<input type="submit" name="submit" value="Save Data">
而且在PHP腳本處理,myprocessingscript.php
:
if (isset($_POST['field1']) && isset($_POST['field2'])) {
$data = 'comments.txt' . $_POST['field1'] . ' ' . $_POST['field2'] . "\n";
$ret = file_put_contents('comments.txt', $data);
if ($ret === false) {
die('There was an error Sending The Comment');
}
else {
echo "The Comment Has Been Sent Succesfully !";
}
}
else {
die('Fill in The Form Please !');
}
if (isset($_POST['field1']) && isset($_POST['field2'])) {
$data = 'comments.txt' . $_POST['field1'] . ' ' . $_POST['field2'] . "\n";
$ret = file_put_contents('comments.txt', $data);
if ($ret === false) {
die('There was an error Sending The Comment');
}
else {
echo "The Comment Has Been Sent Succesfully !";
}
}
else {
die('no post data to process');
}
當我寫的形式的東西到一個文本文件(comments.txt)之前的文字被刪除 - 我該怎麼辦?
什麼是你的問題?而且,你不應該在評論中提問,你應該像你一樣提出新的問題。 – Brad
......有趣的是 - 你還沒有問過一個問題?! – CD001
@Brad我按下輸入是一個錯誤!我修改了20秒! – ShaPesar