Hi,
I am trying to debug a script in PHP 5 (Windows XP,
Apache). It has the feature of displaying lines from a
flat file where individual lines can be deleted.
However, when clicking on delete, it doe snot delete
and I can't figure out why. Below is the relevant
code:
for ($k=0; $k<=count($readfile)-1; $k++) { // This
is standard PHP code for accessing array elements
// This separates each line into fields, separated by
the tab (t)
$fields = split("\t",$readfile[$k]); // This is
standard PHP code for accessing array elements
// This separates each line into fields, separated by
the tab (t)
print("<a
href=\"DeletesRecords.php?delete=$fields[0]\">Delete
this record</a> $fields[0] $fields[1] $fields[2]
$fields[3] $fields[4] $fields[5] $fields[6]<br>");
}
In DeleteRecords.php, here is the relevant extract:
foreach($readfile as $line) { // Read each line in the
file
$fields=explode("\t", trim($line)); // Disect each
line into fields, place each line in any array
// The $delete variable is passed to this script
if ($fields[0]!="$delete") { // If the field does
not match the one to be deleted write everything back
to the file
// Very cool!
fwrite($outfile, $line);
}
}
//print_r ($fields);
//echo 'delete is set as'.$delete;
if ($delete!="") {
print("<strong>Record $delete was
deleted:</strong><br>"); // Affirms that record was
deleted
print("<p align=\"center\"><a
href=\"ManageEmail.php#Addarecord\">Add a record</a> |
<a href=\"SEARCHaRecord.php\">Search for a record</a>
| <a href=\"DELETEaRecord.php\">View all records
refresh</a></p>");
}
Any advice would be much appreciated. Thanks in
advance.
Regards
Dave