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):
<?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.