I have a beginner in PHP. Now I have a very simple question. I have a form and have a submit button. After the user click the submit button, it will save the data in the text file. But now the data in the text area just doesn’t go to the file. the file is empty with a size of 0. I check the code again and again. But I didn’t find anything wrong with it. Could anyone tell me? The following are the html code and the php code.
HTML:
<html>
<head>
<title>question1</title>
</head>
<body bgcolor=”#FFFFFF” text=”#000000″ topMargin=”0″ leftmargin=”0″>
<table cellspacing=”0″ cellpadding=”0″ border=”0″ width=”800″ height=”600″ bgcolor=”#99cc99″>
<tr>
<td valign=”top” height=”566″ align=”center”> <br>
<form name=”question1″ method=”post” action=”saveFunction.php”>
<input type=”text” name=”a1″>
<input type=”submit” name=”Submit” value=”Submit”>
</form>
</td>
</tr>
</table>
</body>
</html>
PHP:
<?php
$fileName = “answerFile.txt”;
if (submit){
// open the file in append mode, if the file doesn’t exist, create one
$handle = fopen ($fileName,’a+’);
chmod ($fileName,0777);
fwrite($handle,$a1);
//close the file
fclose($handle);
}
?>
Thank you very much in advance.