As Danny said a half-dozen posts back, you will have to read the entire file into an array, then rewrite the contents back to the file from the array, with the exception of the one record being edited. You'll rewrite this back to the file from the web form.
The code snippet to accomplish the editing is as follows:
<pre>
// We are updating the record.
$line = file($textfile);
$fd = fopen("$textfile", "w");
/ Open the file in write mode. This erases the file, but we've
already stored all of the contents in $line. Now we want to
write all of the contents back to the file, replacing the values
for $recordNumber with the new values.
/
$x=0; // Index variable
while ($line[$x]) {
if ($x != $recordNumber) {
/ This isn't the record to update, so just write it
back to the file without change.
/
fwrite($fd, $line[$x]);
} else {
/ This is the record to update, so write the updated
info to the file instead of the values that are in the
file. The updated info comes from the web form.
/
// make sure user has not entered a vertical bar in the input
$name = str_replace("|", "", $name);
$email = str_replace("|", "", $email);
// assemble user information
if ($name != "") { // Make sure we have input
$user_row = $name."|".$email."|".$language."|".$job."\n";
fwrite($fd, $user_row) or die("Could not write to file!");
echo "<script language=\"JavaScript\"> ";
echo "location='admin.phtml';"; // Redirect to admin.phtml
echo "</script>";
} else {
print "No name was provided. No data being saved.";
}
} // end if-else
$x++;
} // end while
fclose($fd); // Close the file
</pre>
The above code has been tested and works.