Page 1 of 1

Creating a Saving changed textfield to a txt file

Posted: Mon Jul 17, 2006 7:01 pm
by niksosf
Hello! I'm new to PHP, and I am having trouble to code something that will take a user's text input from, e.g., <span id="address">Enter your address here</span> to create automatically a text file name address.txt on the server with the content of the user's input.

Is this easy to do?

Thank you for your time,

Posted: Mon Jul 17, 2006 7:43 pm
by Ollie Saunders
google HTML forms

Posted: Mon Jul 17, 2006 8:05 pm
by Luke
you will need to know about HTML forms, and I guess mkdir() and definately fopen().

Posted: Tue Jul 18, 2006 6:26 am
by Ollie Saunders
ok i'll help you out a bit more

Code: Select all

<?php
if(!empty($_POST)) {
    $h = fopen('storage.txt', 'a') or exit('Could not open file for writing');
    fwrite($h, $_POST['someInput']) or exit('Could not write to file ');
    fclose($h);
}

?>
<form action="<?php echo basename(__FILE__)?>" method="post"> 
   <label for="someInput">Tell me something</label>
   <input type="text" name="someInput" id="someInput" />
</form>

Posted: Tue Jul 18, 2006 10:21 am
by Luke
Now throw in some error handling & extension testing and you've got yourself a handy little app there, my friend!

Posted: Tue Jul 18, 2006 7:35 pm
by Ollie Saunders
The Ninja Space Goat wrote:Now throw in some error handling & extension testing and you've got yourself a handy little app there, my friend!
yep, i spoil 'em :D