Jump to content

sending text from form to a file...


vipes

Recommended Posts

Hi, I don't know anything about php...but basically i have a form I want to send the info thats put into the form sent to a text file.

Like Login:  Password: i want those 2 variables sent to a text file.

how would I do that exactly?

Can anyone show me a script or something of how its done and what to edit?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/36266-sending-text-from-form-to-a-file/
Share on other sites

if you send your form stuff to the php via post... than it would be something like this. ( i dont know anything much abobut file writing only databases)



fwrite($_POST['field1']);
fwrite($_POST['field2']);
f_write("/n/n");




goodluck

ps that doesnt iclude any validation
your missing a parameter. here. this is how its done. you get your post data, then open the file, write it, then close it.
like this:

[code=php:0]
$username = $_POST['username'];

$handle = fopen('data.txt', 'a'); //the 'a' is the mode. for more modes visit http://au2.php.net/manual/en/function.fopen.php
if(fwrite($handle, "<>".$username)){
echo "Wrote content.";
}else{
echo "Failed writing content.";
}
[/code]

hope that helps.
[quote author=ProjectFear link=topic=124633.msg516852#msg516852 date=1170136710]
your missing a parameter. here. this is how its done. you get your post data, then open the file, write it, then close it.
like this:

[code=php:0]
$username = $_POST['username'];

$handle = fopen('data.txt', 'a'); //the 'a' is the mode. for more modes visit http://au2.php.net/manual/en/function.fopen.php
if(fwrite($handle, "<>".$username)){
echo "Wrote content.";
}else{
echo "Failed writing content.";
}
[/code]

hope that helps.
[/quote]


I tried that but for some reason when I click login it just posts everything in the address bar and shows opens the php file and shows the code....

this is basically what ive got

<h5 class="heading">Member Login</h5>
<form action="myphp.php">
<div class="row">
<label for="email">E-Mail:</label>
<input type="text" name="email" id="email" value="[email protected]" />
</div>
<div class="row">

<label for="password">Password:</label>
<input name="password" type="password" id="password" /><br />
</div>
<div class="clear" style="margin-left:-8px; margin-bottom:3px;">
<input type="checkbox" name="Remember" value="Remember" id="checkbox" checked />
<label for="checkbox">Remember Me</label><br />
</div>
<div style="margin-left:21%">


When someone clicks Login, i want the username and password to be logged to a file....i've been looking up stuff but i cant figure it all out? if someone can tell me what I should put after <form action= and what should the php file say?
You're just seeing the PHP source?  Is it named .php?  Does your webserver support PHP?

To make it sent through post instead of get (the address bar) put method="POST" in the form fthing...

Once you have all that figured out, I, or someone else can help you with the file writing.

Someone else posted while I was typing... But oh well :p
[quote author=corbin link=topic=124633.msg517634#msg517634 date=1170209227]
You're just seeing the PHP source?  Is it named .php?  Does your webserver support PHP?

To make it sent through post instead of get (the address bar) put method="POST" in the form fthing...

Once you have all that figured out, I, or someone else can help you with the file writing.

Someone else posted while I was typing... But oh well :p
[/quote]

i did that, and its still showing the php and yes its named .php and yes it supports php...the box that its ran on is actually owned by dho if anyone knows who that is....anyways, idk why it isnt working...its really getting annoying.
btw this is the php im using

$username = $_POST['username'];

$handle = fopen('data.txt', 'w+');
if(fwrite($handle, "<>".$username)){
echo "Wrote content.";
}else{
echo "Failed writing content.";
}


is there anything in that that should be changed to log the username and password?
In any case he could still use a DB... Even if it is, none of us know what the others do with the knowledge we acquire at this forum... I personally think that anyone here could potentially be trying to learn so he/she can screw others...

Either way, I don't think a kid that doesn't know how to build and handle a form and store the provided info can be a threat to anyone... at least not right now.

Either way, I might be wrong... Or right... all I know is I've had enough of this thread, see you guys around

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.