Schlo_50 Posted June 2, 2008 Share Posted June 2, 2008 Hi there, I have a short list stored as a .DAT file and now I want to be able to edit the last value of each row occasionally. The list is stored in the following format: ID|NAME|CAT_ID. ( E.g 019272516|Papo|18192817261 ) My edit script needs to change the third piece of data in manufacturer.DAT to whatever $relevant is. $mid and $manname which are the first and second pieces of data need to stay what they already are. I have setup a variable ($find_row_by) containing the manufacturer ID so that the text file can be looped through until the correct row is found. Can someone show me the final part to actually editing my .DAT file with the new information please? $find_row_by = $_POST['manid']; if(preg_match('/^(\d+)([a-zA-Z]+)$/',$_POST['manufacturer'],$matches)){ $relevant = $matches[1]; $man = $matches[2]; } $file_name = "data/manufacturers.DAT"; $file_contents= "$mid|$manname|$relevant|\n"; $open_file = fopen($file_name, "a+"); fwrite($open_file, $file_contents); fclose($open_file); echo "<br />Manufacturer successfully added to database.<br /><br /> <meta http-equiv=\"refresh\" content=\"2;URL=?id=operate&action=success\"> "; } Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/108352-editing-one-row/ Share on other sites More sharing options...
DyslexicDog Posted June 2, 2008 Share Posted June 2, 2008 You could use explode() on each row to get your variables. Link to comment https://forums.phpfreaks.com/topic/108352-editing-one-row/#findComment-555488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.