[help] how to make a form that writes to a file

Status
Not open for further replies.

habbz

Custom Title bitchssssssss
Nov 12, 2010
227
1
so my title is a little confusing, but what i want it a form that when you fill it out, it will store that information in a pre-determined file [such as a .txt file that i can view]
can some one tell me how to do this? thanks.
 

habbz

Custom Title bitchssssssss
Nov 12, 2010
227
1
Yeah usually like 2-3 files, in html or something, i learned about it but i for got it. and i really need it and google hates me so yeah.
 

Adil

DevBest CEO
May 28, 2011
1,276
714
Make two div tags
<div>
<FORM action="mailto:[email protected]" method="post" enctype="text/plain">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="90%">
<TR>
<TD width="30%"><DIV align="right">
<B>Name:</B>
</DIV>
</TD>
<TD width="70%">
<INPUT type="text" name="name" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right"><B>Email:</B></DIV>
</TD>
<TD>
<INPUT type="text" name="email" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right">
<B>Comment:</B>
</DIV>
</TD>
<TD><TEXTAREA name="comment" cols="30" wrap="virtual" rows="4">
</TEXTAREA>
</TD></TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<INPUT type="submit" name="submit" value="Submit">
<INPUT type="reset" name="reset" value="Reset">
</TD></TR>
</TABLE>
</FORM>
</div>
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
I just took TheJokers code and made it save to Text.txt :)

HTML:
<div>
<FORM action="save.php" method="post" enctype="text/plain">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="90%">
<TR>
<TD width="30%"><DIV align="right">
<B>Name:</B>
</DIV>
</TD>
<TD width="70%">
<INPUT type="text" name="name" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right"><B>Email:</B></DIV>
</TD>
<TD>
<INPUT type="text" name="email" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right">
<B>Comment:</B>
</DIV>
</TD>
<TD><TEXTAREA name="comment" cols="30" wrap="virtual" rows="4">
</TEXTAREA>
</TD></TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<INPUT type="submit" name="submit" value="Submit">
<INPUT type="reset" name="reset" value="Reset">
</TD></TR>
</TABLE>
</FORM>
</div>

And then save.php
PHP:
<?php
$fp = fopen("Text.txt", "a");
fwrite($fp, "Name: $_POST[name]\nEMail: $_POST[email]\nComment: $_POST[comment]\n\n\n\n\n<hr>\n");
echo "Thanks for the feedback!";?>

Also.

Text.txt has to have CHMOD of 777.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
I just took TheJokers code and made it save to Text.txt :)

HTML:
<div>
<FORM action="save.php" method="post" enctype="text/plain">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="90%">
<TR>
<TD width="30%"><DIV align="right">
<B>Name:</B>
</DIV>
</TD>
<TD width="70%">
<INPUT type="text" name="name" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right"><B>Email:</B></DIV>
</TD>
<TD>
<INPUT type="text" name="email" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right">
<B>Comment:</B>
</DIV>
</TD>
<TD><TEXTAREA name="comment" cols="30" wrap="virtual" rows="4">
</TEXTAREA>
</TD></TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<INPUT type="submit" name="submit" value="Submit">
<INPUT type="reset" name="reset" value="Reset">
</TD></TR>
</TABLE>
</FORM>
</div>

And then save.php
PHP:
<?php
$fp = fopen("Text.txt", "a");
fwrite($fp, "Name: $_POST[name]\nEMail: $_POST[email]\nComment: $_POST[comment]\n\n\n\n\n<hr>\n");
echo "Thanks for the feedback!";?>

Also.

Text.txt has to have CHMOD of 777.
PHP:
<?php fclose( $fp ); ?>
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
I just took TheJokers code and made it save to Text.txt :)

HTML:
<div>
<FORM action="save.php" method="post" enctype="text/plain">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="90%">
<TR>
<TD width="30%"><DIV align="right">
<B>Name:</B>
</DIV>
</TD>
<TD width="70%">
<INPUT type="text" name="name" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right"><B>Email:</B></DIV>
</TD>
<TD>
<INPUT type="text" name="email" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right">
<B>Comment:</B>
</DIV>
</TD>
<TD><TEXTAREA name="comment" cols="30" wrap="virtual" rows="4">
</TEXTAREA>
</TD></TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<INPUT type="submit" name="submit" value="Submit">
<INPUT type="reset" name="reset" value="Reset">
</TD></TR>
</TABLE>
</FORM>
</div>

And then save.php
PHP:
<?php
$fp = fopen("Text.txt", "a");
fwrite($fp, "Name: $_POST[name]\nEMail: $_POST[email]\nComment: $_POST[comment]\n\n\n\n\n<hr>\n");
echo "Thanks for the feedback!";?>

Also.

Text.txt has to have CHMOD of 777.
This is a single file correct?
What's the second file called?
I'm an idiot, Thank you.
EDIT:
It doesn't store what the user puts in
This is what my Text.txt file reads:
Code:
Name:
EMail:
Comment:
   
<hr>
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
Maybe your server requires fclose.

PHP:
<?php
$fp = fopen("Text.txt", "a");
fwrite($fp, "Name: $_POST[name]\nEMail: $_POST[email]\nComment: $_POST[comment]\n\n\n\n\n<hr>\n");
echo "Thanks for the feedback!";
fclose($fp);
?>
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,926
3,921
Perhaps try this:
PHP:
<?php
$fp = fopen("Text.txt", "a");
fwrite($fp, "Name: {$_POST['name']}\nEMail: {$_POST['email']}\nComment: {$_POST['comment']}\n\n\n\n\n<hr>\n");
fclose($fp);
echo "Thanks for the feedback!";
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
If that does not work, try this HTML code for the page.

HTML:
<div>
<FORM action="save.php" method="POST">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="90%">
<TR>
<TD width="30%"><DIV align="right">
<B>Name:</B>
</DIV>
</TD>
<TD width="70%">
<INPUT type="text" name="name" id="name" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right"><B>Email:</B></DIV>
</TD>
<TD>
<INPUT type="text" name="email" id="email" size="20">
</TD>
</TR>
<TR>
<TD><DIV align="right">
<B>Comment:</B>
</DIV>
</TD>
<TD><TEXTAREA name="comment" id="comment" cols="30" wrap="virtual" rows="4">
</TEXTAREA>
</TD></TR>
<TR>
<TD>&nbsp;</TD>
<TD>
<INPUT type="submit" name="submit" value="Submit">
<INPUT type="reset" name="reset" value="Reset">
</TD></TR>
</TABLE>
</FORM>
</div>
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
Maybe your server requires fclose.

PHP:
<?php
$fp = fopen("Text.txt", "a");
fwrite($fp, "Name: $_POST[name]\nEMail: $_POST[email]\nComment: $_POST[comment]\n\n\n\n\n<hr>\n");
echo "Thanks for the feedback!";
fclose($fp);
?>
This didn't work.
Perhaps try this:
PHP:
<?php
$fp = fopen("Text.txt", "a");
fwrite($fp, "Name: {$_POST['name']}\nEMail: {$_POST['email']}\nComment: {$_POST['comment']}\n\n\n\n\n<hr>\n");
fclose($fp);
echo "Thanks for the feedback!";
This also didn't
But when i changed the HTML code and used rasta's code it worked.

Thanks guys :)
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
Ah I see, I placed the fclose after the echo, I haven't used fwrite in forever and was just going off what I recalled :p

But glad to see you got it, and glad to help.
 
Status
Not open for further replies.

Users who are viewing this thread

Top