Re: store data without db
| From: | David Robley | Date: | Wed, 30 Aug 2000 02:57:22 +0000 |
| Subject: | Re: store data without db | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14291@lists.php.net to get a copy of this message | ||
On 30 Aug, kelvin wrote:
>
>
> Hi,
>
> I've problem with store data in textfile...
>
> if ($do=="booking" && $no!="") {
> $fp = fopen("database","r");
> $data = fgets($fp,30000);
> fclose($fp);
> $data = ereg_replace("$no;0;Empty;\n", "$no;1;Some_name;\n", $data);
>
> $fw = fopen("database","w");
> $update = fputs($fw,$data);
> fclose($fw);
> }
>
> the error i get, file 'database' only contain 1 line & the other line
> are gone...
>
> database file (there's 200 lines):
>
> 10;0;Empty;
> 11;0;Empty;
>
> Kelvin
$fw = fopen("database","w");
truncates your file to zero length. Read the documentation on fopen
again and look at the 'mode' values, particularly 'a' for append. You
may have to rethink your data finding section, remembering that fgets
only returns up to a newline.
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA