I want to create a registration system on my site where only limited users will be able to create their account. I want to use a .txt file for storing usernames and passwords.

I have the following code so far :

```
$uname=$_POST['usr'];
$pass=$_POST['pwd'];

if(empty($_POST["ok"])){echo "Could not insert data!";}
 else
{$file=fopen("user.txt","w");
echo fwrite($file,$uname);
fclose($file);}

```

This receives the user data from a form and puts it in user.txt file.

My problem is that when new data is inserted to txt file the old data get deleted.

I want to keep the data in txt file like 

```
  foo:12345~bar:1111

```

username and password are seprated by **:** and new user is seprated by **~** ,later I will use regex to get the data from txt file.

How can i correct my code to keep both new and old data?