Hi All,
I am at my wits end with some code for a website I am working on. The page in question is simply for a user to add items to a list of data. The data is stored in a temp file and later added to a database. I have successfull set the page to add items to the list of data. My issue is with trying to remove a line of data from the file. The following snippet of code runs if a link has been clicked on the line of data to be removed which reloads the page running this code which is intended to remove that line...
if ( isset($RemoveLine) ) {
//file() opens a file and puts the content in an array
//each element of the array is a line
$fileText = file($filename);
$CheckLine = 0;
//open the file again
$f = fopen($filename, 'w');
foreach($fileText as $line){
$Checkline = $Checkline + 1;
if ($CheckLine <> $RemoveLine){
fputs($f,$line); //place $line back in file
}
}
fclose($f);
unset($RemoveLine);
}
Before clicking the link to remove a line my page displays the following detail for example...
Qty Code Description Unit Price (£) Total (£) + V.A.T
2 2 2 2 2 0.33 Remove Item
3 3 3 3 3 0.495 Remove Item
4 4 4 4 4 0.66 Remove Item
However after clicking Remove Item (for this example I clicked Remove Item on the second line) the page reloads with the following...
Qty Code Description Unit Price (£) Total (£) + V.A.T
2 2 2 2 2 0.33 Remove Item
3 3 3 3 3 0.495 Remove Item
4 4 4 4 4 0.66 Remove Item
4 4 4 4 0 Remove Item
I have checked the temp file being used and the data matches that displayed...
2, 2, 2, 2, 2, 17.5
3, 3, 3, 3, 3, 17.5
4, 4, 4, 4, 4, 17.5
4, 4, 4, 4, ,
Annoyingly my remove item link is adding another line instead of removing the chosen line.
Any help with this would be fantastic.
Thanks
Adrian