2016-06-29 63 views
-1

我有一個簡單的HTML表單,包含複選框和文本字段。PHP - 將表單數據保存到兩個不同的文本文件

當我提交此表單時,它將數據提交回我捕獲數據並將其寫入文本文件的同一頁面。

我想嘗試做的事情是將一些複選框和字段數據寫入一個文本文件,其餘部分寫入另一個文本文件。

可以這樣做嗎?如果它可以怎麼說哪些字段被寫入哪個文件?

謝謝

+3

你寫的代碼。 'file_put_contents('1.txt',$ somevalue); file_put_contents('2.txt',$ othervalue);' –

+1

讓我們看看你的代碼(發佈)。 –

+1

請在這裏發佈您的代碼 –

回答

1

您發送您的表單,然後處理數據。例如:

$dog = $_POST["dog"]; 
$cat = $_POST["cat"]; 

$fileForDogs = fopen('path://to/first/file', 'a+'); //a+ means if not exst, create one and write on the end of file 
fwrite($fileForDogs, $dog); 
fclose($fileForDogs); 

$fileForCats = fopen('path://to/second/file', 'a+'); //a+ means if not exst, create one and write on the end of file 
fwrite($fileForCats, $cat); 
fclose($fileForCats); 

我強烈建議查看數據庫例如mysql來保存表單中的數據。

相關問題