我創建了一個表單,用戶需要在第一個文本字段處插入名稱並在第二個文本字段一個(一些信息)。 這是我爲我的表單代碼:獲取文本框的內容,從中創建一個.txt文件並將其存儲到數據庫中
echo "<form method='post' action='insert.php?selected=$openFolder&id=$student'>
Information name:</br> <input name='infoName' type='text' /><br />
Information:<br />
<textarea name='text' rows='15' cols='60'>
</textarea><br />
<input type='submit' name='submit' value='Submit Information'/>
</form>";
到目前爲止好。
現在,當表單提交我需要創建一個文件:
文件名 - >名用戶在「infoName」文本字段
插入然後插入內容'文本'文本字段放入此文件並將整個文件存儲到我的數據庫中。
這裏是我的代碼:
if (isset($_POST['submit']))
{
//Make sure that a file name is given by the user
if (!$_POST['infoName'])
{
echo "<center><font color='red'>You must complete the Information name field</font></center>";
}
else
{
$informationName = $_POST['infoName'];
$informationContent = $_POST['text'];
$newFile = fopen($informationName,"w");
$content = fwrite($newFile,$informationContent . "\n");
$content = addslashes($content);
fclose($newFile);
$theSize = filesize($informationName);
if(!get_magic_quotes_gpc())
{
$informationName = addslashes($informationName);
}
$query = "INSERT INTO $openFolder (studentID, name, size, type, content, insertedBy) ".
"VALUES ('$student','$informationName', '$theSize', 'txt', '$content', '$username')";
mysql_query($query) or die('Error, query failed');
}
}
我的問題:
1)文件被創建正確的,並且存儲在我的數據庫,但與沒有它的正確內容。出於某種原因,我沒有插入正確的文本到文件中...
2)除了存儲在我的數據庫中的文件,在我的目錄中創建了一個文件,我不希望發生這種情況。
請幫助我。隨意對我的代碼進行任何更改! 請告訴我什麼即時做錯了!