Hey. i was wondering howto delete a single line from a FFD

on the server that i currently have, it is not possible to use a mySQL database and I'd rather keep it a FDD

I have tried too no avail.

Here is my current code

<?php

$file = fopen('clients.txt','r');
$id = $_REQUEST['id'];

for ($i=0; $i<count($file); $i++) 
{
	list ($field1, $field2, $field3, $field4) = split ('\|', $i);
	if ($field1!=$id) 
	{ 
		$data .= $field1.'|'.$field2.'|'.$field3.'|'.$field4."\n"; 
	}
} 
fclose($file);
$fp = fopen('clients.txt','w');
fwrite($fp,$data);
fclose($fp); 
?>

and my friend suggested putting it all in a table, and deleting the line, and overwriting the file.
no idea of how to do this....

Oh, my database is kinda like this.

23453|maxicube|admin|305
23454|fish|user|28

Also, if i run that.
this is all that returns on clients.txt

0|||

thanks for your help - Maxicube :D

Recommended Answers

All 7 Replies

what about writing the entire thing in some other file except that particular line & then deleting the first file,making the second file as main FFD.
Or even think about having the unique field value for the records, as a line numbers, so that it will be easy to delete

GAH!
tried doing that, to no avail.

new code:

<?php

$file = fopen('clients.txt',r);
$ip = $_SERVER['REMOTE_ADDR'];

$fp = fopen('client.txt','a')
for ($i=0; $i<count($file); $i++) 
{
	list ($field1, $field2, $field3, $field4) = split ('\|', $i);
	if ($field1!=$ip) 
	{ 
		fwrite($fp,$i."\n"); 
	}
} 
fclose($fp); 
?>7

new error

Parse error: syntax error, unexpected T_FOR in *snip*/test.php on line 7

Take a look at line 6, you are missing a ; which is the reason for that error.

*sigh* silly me - just woke up
ok, now thats out of the way.
all that returns in the client.txt (not clients.txt)
is the number 0.

<?php $file = fopen('clients.txt',r);
$fp = fopen('client.txt','a');
$ip = $_SERVER['REMOTE_ADDR']; 
for ($i=0; $i<count($file); $i++) {
$list=fgetcsv( $file,1000,'|');	
if ($list[0]!=$ip) { fputcsv($fp,$list,'|'); } }
fclose($fp);
fclose($file);  ?>

have not verified syntax this is a thought exercise

after cleaning your code.

<?php
$file = fopen('clients.txt','r');
$ip = $_SERVER['REMORE_ADDR'];
$fp = fopen('client.txt','a');

for ($i=0; $i<count($file); $i++)
{
	$out = fgetcsv($file,1000,'|');
	if ($out[0]!=$ip)
	{
		fwrite($fp,$out);
	}
fclose($fp);
fclose($file);
}
?>

it spits out "ArrayArray" into client.txt

have not verified syntax this is a thought exercise

You can find how to solve the syntax problem in the php manual
I pulled that code out of my **expletive deleted**

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.