wansell Posted June 1, 2006 Share Posted June 1, 2006 Hi All,Sorry if this is in the wrong category, but it seems the flat database category in the forum has been closed down...Anyway my problem. I would like to be able to edit/modify just one field in my flat database. The fields are seperated by "|". I have a form that you can edit all the fields, but i think this relys on the other form fields filling the other database fields.I just want this script to open the databse change a number in the database in a particular field, save it and then close it.Is this possible, and how would i acheive this.ThanksWayne Ansell Quote Link to comment https://forums.phpfreaks.com/topic/10960-flat-database-help/ Share on other sites More sharing options...
Barand Posted June 1, 2006 Share Posted June 1, 2006 Not very sophisticated, but this will allow you to edit a flat (delimited text) file .(Remove '_' from f_open, f_write, f_close)[code]<?php$filename = 'test.txt';$delim = '|';if (isset($_POST['submit'])) { $fp = f_open($filename, 'w'); foreach($_POST['field'] as $record) { $data = join($delim, $record) . "\n"; f_write($fp, $data); } f_close ($fp);}?><FORM action="" method="POST"><TABLE border='1' cellspacing='0' cellpadding='4'> <?php $file = file($filename); $rec = 0; foreach ($file as $line) { $line = trim($line); $fields = explode($delim, $line); //headings if ($rec==0) { echo "<TR>\n"; echo "<TD>Rec #</TD>\n"; foreach ($fields as $k => $val) { echo "<TD>\n"; echo 'Field ', $k+1; echo "</TD>\n"; } echo "</TR>\n"; } echo "<TR>\n"; echo '<TD>',$rec+1,"</TD>\n"; foreach ($fields as $val) { echo "<TD>\n"; $sz = strlen($val); echo("<INPUT type='text' name='field[$rec][]'value='$val' size='$sz'"); echo "</TD>\n"; } echo "</TR>\n"; $rec++; } ?></TABLE><INPUT type="submit" name="submit" value="Submit"></FORM>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10960-flat-database-help/#findComment-41030 Share on other sites More sharing options...
poirot Posted June 2, 2006 Share Posted June 2, 2006 When using Flatfiles, I like to use the serialize functions:[a href=\"http://www.php.net/serialize\" target=\"_blank\"]http://www.php.net/serialize[/a]Less headaches with explode (which can be very unreliable) Quote Link to comment https://forums.phpfreaks.com/topic/10960-flat-database-help/#findComment-41057 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.