2011-12-20 31 views
-1

我一直在修復一個錯誤,在那裏我提交一個html表單,並從該表單獲取信息並將其用於php腳本中,並將其保存到文件中。在Chrome和Firefox中,它可以保存數據,沒有問題。然而,在IE中,無論是表單提交怪異還是php混亂,重複10次保存數據。所以,而不是「測試」,我得到「TestTestTestTestTest..ect」在IE中奇怪的重複php fwrite

有人知道爲什麼這隻會發生在IE瀏覽器?

通用代碼(不是全部包括。不過,這是大多隻是這種重複):

<form id="form1" action="createProf.php" method="post"> 

<input type="radio" style="position:absolute; top: 218px; left: 560px;" id="female" name="gender" value="female"/> 
<input type="radio" style="position:absolute; top: 187px; left: 560px;" id="male" name="gender" value="male"/> 
<input type="text" id="year" name="year" size="4" value="Year" style="position:absolute; top: 416px; left: 640px;"/> 
</form> 

    //php code// 
$gender = htmlspecialchars($_POST['gender']); 
$acc = fopen($file, 'r') or die("cant open file"); 
//other reading code and other stuff ehre 
fwrite($acc, $data); 
fclose($acc); 

感謝了,如果還需要更多的幫助,我願意補充更多。

+1

你如何寫一個文件,你只打開閱讀? – Rufinus 2011-12-20 02:31:16

+0

好點..我複製了錯誤的代碼,這是從我意圖發佈的10行起: $ acc = fopen($ file,'w')或die(「cant open file」); fwrite($ acc,$ data); – user747638 2011-12-20 02:33:00

+0

$數據是如何填充的?好像你忽略了重要的代碼。 – 2011-12-20 02:33:05

回答

0

顯然我說過一些人不回答我和-1我的帖子。

無論如何,我找到了一個答案,我只是檢查是否已經存在最後一次保存的數據,然後我不寫入並關閉文件。我希望有一個更清潔的方式,但我想現在這是我必須使用的。

if(strpos(fread($acc, filesize($file)), "identification_string")==false){ 
//Write to file 
}