Creating a Saving changed textfield to a txt file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
niksosf
Forum Newbie
Posts: 1
Joined: Mon Jul 17, 2006 6:57 pm

Creating a Saving changed textfield to a txt file

Post 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,
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

google HTML forms
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

you will need to know about HTML forms, and I guess mkdir() and definately fopen().
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Now throw in some error handling & extension testing and you've got yourself a handy little app there, my friend!
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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
Post Reply