Jump to content

Update a txt files rows with a form?


adige

Recommended Posts

yes I know that but I dont want it.I have a text file.

 

What the?! Did you even LOOK at the links he posted? One was on creating forms in PHP and the other was for modifying files. Isn't that what you want to do?

 

I had already completed this before I read that response of yours which suggests you can't even take the time to look at the information provided to you. So, I'll post this anyway, but I do so with hesitation

 

<?php
$fileName = "temp.txt";
$lineToEdit = 10;

if(isset($_POST['editLine']))
{
    $lines = file($fileName, FILE_IGNORE_NEW_LINES);
    $editLine = $_POST['editLine'];
    $lines[$lineToEdit-1] = $editLine;
    $fh = fopen($fileName, 'w') or die("can't open file");
    fwrite($fh, implode("\n", $lines));
    fclose($fh);
}
//Get 10th line from 
if(!isset($line10))
{
    $lines = file($fileName, FILE_IGNORE_NEW_LINES);
    $editLine = (isset($lines[$lineToEdit-1])) ? $lines[$lineToEdit-1] : '';
}

?>
<html>
<body>
<form method="POST">
Value of line <?php echo $lineToEdit; ?>:<br />
<input type="text" style="width:300px;" name="editLine" value="<?php echo $editLine; ?>" /><br /><br />
<button type="submit">Change Value</button>
</form>
<?php
    //This block of code for debugging purposes only
    echo "<pre>\n";
    print_r($lines);
    echo "</pre>\n";
?>
</body>
</html>

Link to comment
Share on other sites

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.