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? Link to comment https://forums.phpfreaks.com/topic/216265-update-a-txt-files-rows-with-a-form/ 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. Link to comment https://forums.phpfreaks.com/topic/216265-update-a-txt-files-rows-with-a-form/#findComment-1123892 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 Link to comment https://forums.phpfreaks.com/topic/216265-update-a-txt-files-rows-with-a-form/#findComment-1123895 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 Link to comment https://forums.phpfreaks.com/topic/216265-update-a-txt-files-rows-with-a-form/#findComment-1123896 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 Link to comment https://forums.phpfreaks.com/topic/216265-update-a-txt-files-rows-with-a-form/#findComment-1123897 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> Link to comment https://forums.phpfreaks.com/topic/216265-update-a-txt-files-rows-with-a-form/#findComment-1123918 Share on other sites More sharing options...
adige Posted October 19, 2010 Author Share Posted October 19, 2010 thank you damato Link to comment https://forums.phpfreaks.com/topic/216265-update-a-txt-files-rows-with-a-form/#findComment-1123922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.