Jump to content

Recommended Posts

So I'm working on a php page that can edit a .txt-file.

This is what I'v got so far:

<?php 
if (isset($_POST['submit'])) {  

$stringData = stripslashes($_POST['sf']);  
file_put_contents("huisrekening.txt", $stringData); 

header('Location: quaestor.php?a=update');  

}  
?> 

Huisrekening: 
<form action="" method="post"> 
<textarea name="sf" cols="100" rows="20"> 
<?php 
$theData = file_get_contents("huisrekening.txt"); 
echo $theData;  
?></textarea> 
<br /> 
<input type="submit" name="submit" value="Update" /> 
</form> 

<?php 
if ($_GET['a'] == 'update') { 
echo ''; 

$myFile = "huisrekening.txt"; 
$fh = fopen($myFile, 'r'); 
$theData = fgets($fh); 
fclose($fh); 
echo $theData; 

} 
?>

 

Problem: each time I hit the Update button an extra line appears in the .txt-file. :-(

Does anybody know what I did wrong?

Link to comment
https://forums.phpfreaks.com/topic/237800-edit-txt-files-from-1-php-page/
Share on other sites

I'm just starting out with php. What exactly do you mean by trimming?

 

Edit:

This is what my goal is: a page with data, only one person (with password) is able to edit is via his browser (so without using ftp).

I did play a little bit with Drupal, Wordpress and Joomla, but those CMS are too big and I have a perfect html/css website template (my own ^^) at the moment, don't want to change that.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.