# Deleting entry from text file

**URL:** <https://forum.kirupa.com/t/deleting-entry-from-text-file/253868>\
**Category:** programming\
**Created:** [March 5, 2008, 10:49pm UTC](https://forum.kirupa.com/t/deleting-entry-from-text-file/253868 "2008-03-05T22:49:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [March 5, 2008, 10:49pm UTC](https://forum.kirupa.com/t/deleting-entry-from-text-file/253868/1 "2008-03-05T22:49:03Z")

</div>

This relates to another post I have going - here’s some PHP script that adds a user/password combination to a text file (encrypting the password):

```auto

<?php

if (isset ($_POST['submit'])) {
$problem = FALSE;
}

if (empty ($_POST['username'])) {
  $problem = TRUE;
echo 'please enter a username!';
}

if (empty ($_POST['password'])) {
  $problem = TRUE;
echo 'Please enter a password';
}

if (empty ($_POST['password2'])) {
  $problem = TRUE;
echo 'Your password did not match your confirmed password';
}

if ( !$problem ) {
 
if ($fp = fopen ( 'users.txt', 'ab' ) { //Open the file!
$dir = time() . rand 90, 4596);
$data = $_POST['username'] . "	" . crypt($_POST['password'] . "	" . $dir . "
";

// Write data and close file!
fwrite ( $fp, $data );
fclose ( $fp );

mkdir ( $dir )

echo 'You are now registered!';

} else {
   echo 'You could not be registered due to an error';
}

} else {
echo 'Please try again!';
}
?> 

```

What I’m wondering is how to delete entries as well. Easy enough to create the HTML form with a delete button but I could use help with the PHP delete functionality.
