Need Help Appending to file


#1

I have this script that will move the data from one text file to another but I’ve not figured out how append new data to the “moving” data, my script is below:

[php]

Problem Tracker <?php $file_contents = file("map-research-data.txt"); // the file $file_contents_deleted = file("map-deleted.txt"); // the file // [ DELETE ROUTINE ] if($_POST['action'] == "delete"){ // delete triggered $arrToDelete = $_POST['todelete']; // assign checked items array to var if($arrToDelete != "") { // if the array isnt open proceed foreach($arrToDelete as $key => $value) { // assign a key and value to each checked item $file_contents_deleted[] = $file_contents[$key]; array_splice($file_contents, $key, 1, ""); // assign null value to each checked item in file_contents array print("Removed $value Issue From Pending List
"); } $sizeof = count($file_contents_deleted); // count updated file_contents array if($filehandle = fopen("map-deleted.txt", "w")){ // open the file for writing for($y = 0; $y < $sizeof; $y++){ // loop through the new file_contents array if($file_contents_deleted){ fputs($filehandle, $file_contents_deleted[$y]); // write the new file_contents array to the file } } fclose($filehandle); // close the file } $sizeof = count($file_contents); // count updated file_contents array if($filehandle = fopen("map-research-data.txt", "w")){ // open the file for writing for($y = 0; $y < $sizeof; $y++){ // loop through the new file_contents array if($file_contents){ fputs($filehandle, $file_contents[$y]); // write the new file_contents array to the file } } fclose($filehandle); // close the file } } } ?> <?php // [ READ & OUTPUT FILE CONTENTS ] ?>
Pending Problem Issues

Problem Tracker

<?php $file_contents = file("map-research-data.txt"); // the file foreach($file_contents as $key=> $value){ // assign a key to each line in the file if($file_contents[$key] != ""){ $entry = explode(",", $file_contents[$key]); // break out each delimeter - tab in this case $entries[]=array('user'=>$entry[0], 'dept'=>$entry[1],'datedone'=>$entry[2],'timedone'=>$entry[3], 'upc'=>$entry[4], 'title'=>$entry[5],'product'=>$entry[6], 'problem'=>$entry[7], 'note'=>$entry[8], 'key'=>$key, 'value'=>$value); } } if ($entries) { foreach ($entries as $key => $row) { $user[$key] = $row['user']; $dept[$key] = $row['dept']; $datedone[$key] = $row['datedone']; $timedone[$key] = $row['timedone']; $upc[$key] = $row['upc']; $title[$key] = $row['title']; $product[$key] = $row['']; $problem[$key] = $row['problem']; $note[$key] = $row['note']; } switch ($sort) { case "user": array_multisort($user, SORT_ASC, $entries); break; case "dept": array_multisort($dept, SORT_ASC, $entries); break; case "datedone": array_multisort($datedone, SORT_ASC, $entries); break; case "timedone": array_multisort($timedone, SORT_ASC, $entries); break; case "upc": array_multisort($upc, SORT_ASC, $entries); break; case "title": array_multisort($title, SORT_ASC, $entries); break; case "product": array_multisort($, SORT_ASC, $entries); break; case "problem": array_multisort($problem, SORT_ASC, $entries); break; case "note": array_multisort($note, SORT_ASC, $entries); break; } } for($i=0; $i<sizeof($entries); $i++) { print(""); } ?>

User

Department

Date

Time

UPC Scanned

Title

product

Problem

Note

Has Issue Been Resolved?

".$entries[$i]['user']."

".$entries[$i]['dept']."

".$entries[$i]['datedone']."

".$entries[$i]['timedone']."

".$entries[$i]['upc']."

".$entries[$i]['title']."

".$entries[$i]['']."

".$entries[$i]['problem']."

Check All ?



[/php]

I need to be able to append via the text box with the note key

MOD BREAK: Surrounded code with [php] tags, and applied indenting


#2

What have you tried so far?
What errors did you get when trying those things?
What have you searched on the regular search engines, and what was the results?
Why did those results not suit your needs?
What did you search for on the PHP manual?

Appending text to a file isn’t all that hard, it’s explained in the PHP manual how to manipulate remote files in various ways.


#3

I’m not exactly sure where your problem lies, but one suggestion is to look through this tutorial on files, and file handling. :)

Hope you’re able to find your answers!

-Teh Riddler