update / edit record in textfile database via value passed by link

Hi,

I am currently keeping track of some open case request form data in a textfile database, but now would need to provide the users with a link to change their case status from OPEN to CLOSED.

While I can manage to generate a link that deletes the exisiting redord in the database and then write the case again with $case_status as closed, I was wondering if there is any way for me to loop through the existing records, identify the line/record I want via the $time value, and then merely change the respective $caste_status? Would be much cleaner instead of deleting & re-writing the entire record…

This is how I write into the textfile:

if	(	isset($staff_name) && isset($problem) && isset($incident) && isset($case_status)	)
				{
					$data = $time . '|' . $staff_name . '|' . $staff_department . '|' . $problem . '|' . $priority . '|' . $gst_name . '|' . $gst_room . '|' . $incident . '|' . $action . '|' . $followup . '|' . $gst_temp . '|' . $case_status . '|' . $gst_history . "\n";
					$ret = file_put_contents('GPAdata.txt', $data, FILE_APPEND | LOCK_EX);
					
					if	($ret === false)	
						{
						die('There was an error writing this file');
						}
				}

this is what I got so far in regards to finding and deleting the record:

<?php

$Lines = file("GPAdata.txt");
$cLines = count($Lines);
$dlete = $_GET['time'];

  foreach($Lines as $Key => $Val) { 

   $Data[$Key] = explode("|", $Val);

    if ( trim($Data[$Key][1]) == $dlete ) {

     unset($Lines[$Key]);
     $fp = fopen("GPAdata.txt", "w");
     $fw = fwrite($fp, implode('', $Lines));
     fclose($fp);

    }
  }

print "Deleted";

?>

Now I just need some guidance on how to match the time to a specific record in the database and then change that lines $case_status value from “open” to “closed”.

Thanks a lot!
A2k

I think you need to consider writing a case record. Otherwise, you will need to match on all unique fields, tedious to do in a text file.

Sponsor our Newsletter | Privacy Policy | Terms of Service