PDA

View Full Version : Write info from a input form...



Verrou
15-01-2008, 04:14 AM
Does anyone have the script to write the information from an input field to a .txt file when the submit button is pressed?

I need it to insert a name with a proceeding comma.

So the .txt file would look something like this:
André,Frank,Bamaloo,Bob,Joe,Verrou

Any help = +rep.

Thanks,
Ver.

Scania
15-01-2008, 08:20 AM
Search it up on google? Or go to websites that contain design codes etc.

Jme
15-01-2008, 10:56 AM
Not really sure but something like this probably..


<?php
if(isset($_POST['submit'])) // Forms submitted..
{
$field = $_POST['field'];
$file = "yourfile.txt"; //File you're wanting to write to

file_put_contents($file, $field);
echo("Inserted..");
}
else
{
echo("<form method=\"post\">
<input type=\"text\" name=\"field\" /><br />
<input type=\"submit\" name=\"submit\" value=\"write\" />
</form>");
}
?>

make sure your txt file has write permissions.

Blob
15-01-2008, 05:44 PM
<?php
$text = "HIDER";
$file = fopen( 'text.txt', 'a' );
$file = fwrite( $file, $text );
$file = fclose( $file );
?>

Aint tested... Should work

Mentor
15-01-2008, 05:52 PM
<?php
$text = "HIDER";
$file = fopen( 'text.txt', 'a' );
$file = fwrite( $file, $text );
$file = fclose( $file );
?>

Aint tested... Should work
Yep though it would probs be best to add a newline or space in to it, so there's some separation between the values :P

Verrou
15-01-2008, 07:06 PM
JME, yours worked perfectly, thanks heaps.

+rep to JME and blob.

MrCraig
15-01-2008, 08:06 PM
:S would JME's vers not rewrite the whole file every time?

Jme
15-01-2008, 10:18 PM
:S would JME's vers not rewrite the whole file every time?

Ye it would, isn't that what he wanted? haha, idk, maybe i didn't understand what he was asking.

chrisgocrazyH
17-01-2008, 04:58 AM
Not really sure but something like this probably..


<?php
if(isset($_POST['submit'])) // Forms submitted..
{
$field = $_POST['field'];
$file = "yourfile.txt"; //File you're wanting to write to

file_put_contents($file, $field);
echo("Inserted..");
}
else
{
echo("<form method=\"post\">
<input type=\"text\" name=\"field\" /><br />
<input type=\"submit\" name=\"submit\" value=\"write\" />
</form>");
}
?>
make sure your txt file has write permissions.



Yes uhhmm if i had test.php and used that insted of text.txt will that work :)

Jme
17-01-2008, 01:27 PM
Yes uhhmm if i had test.php and used that insted of text.txt will that work :)

No because that would create a syntax error.

Hitman
17-01-2008, 01:33 PM
Yes uhhmm if i had test.php and used that insted of text.txt will that work :)You want the PHP file to be written to?

Write it to a .txt file, then include the .txt file on the PHP page maybe? Might work. :P

Want to hide these adverts? Register an account for free!