Jump to content

Flat Database help


wansell

Recommended Posts

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.

Thanks
Wayne Ansell
Link to comment
https://forums.phpfreaks.com/topic/10960-flat-database-help/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/10960-flat-database-help/#findComment-41030
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.