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,
Creating a Saving changed textfield to a txt file
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
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>- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK