adige Posted October 19, 2010 Share Posted October 19, 2010 Hi, I want to update a txt files 10. row with a form but I could not it how can I do it? Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 19, 2010 Share Posted October 19, 2010 Perhaps if you explained your problem better and showed the code you have we could help you. I have no idea what you mean by "I want to update a txt files 10. row with a form...". Give an example of the input and the output. Quote Link to comment Share on other sites More sharing options...
adige Posted October 19, 2010 Author Share Posted October 19, 2010 I have example.txt file.I want to update it files fows by a form.But I cant update it Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 19, 2010 Share Posted October 19, 2010 forms - http://www.w3schools.com/php/php_forms.asp using text files - http://www.tizag.com/phpT/filewrite.php Quote Link to comment Share on other sites More sharing options...
adige Posted October 19, 2010 Author Share Posted October 19, 2010 yes I know that but I dont want it.I have a text file. example.txt bla bala bala bla bala kskskkskskskskks >>>I want to update only this row kskskskskksksksk Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 19, 2010 Share Posted October 19, 2010 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> Quote Link to comment Share on other sites More sharing options...
adige Posted October 19, 2010 Author Share Posted October 19, 2010 thank you damato Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.