/    Sign up×
Community /Pin to ProfileBookmark

has trouble in getting form data

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.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pyroJul 29.2003 — The problem could be the global variables are off. Take a look at http://www.webdevfaqs.com/php.php#globalvariables
Copy linkTweet thisAlerts:
@mililyauthorJul 29.2003 — Pyro , thank you so much. It is working now.
Copy linkTweet thisAlerts:
@pyroJul 29.2003 — You're welcome... Glad to see the http://www.webdevfaqs.com is coming in handy... We just put it live today!
×

Success!

Help @milily spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...