I am just doing a homework don't ask me why i don't use SQL for this.
This is what my program does, it has a registration form that generates a .txt file with the username password and phone number. The pattern that generates the user info is this: $username|$phone|$password, so you can see they are separated with a | and with every new creation in the .txt file it goes on a new line. Everything works fine in the registration form. What i need to do now is create a change password form that searches for the $username and $phone, i did manage that but after finding the existing information i should alter the $password from the .txt file and i don't know how, this is what i have done so far:
HTML:
<form method="POST" action="change.php">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" placeholder="Enter username" name="username" />
</div>
<div class="form-group">
<label for="telephone">Telephone:</label>
<input type="text" class="form-control" placeholder="Enter thelephone" name="phone" />
</div>
<button type="submit" class="btn btn-secondary">Register</button>
</form>
change.php:
$username = $_POST['username'];
$phone = $_POST["phone"];
$users = file_get_contents("users.txt");
$users = trim($users);
$users = explode(PHP_EOL, $users);
foreach ($users as $user) {
$user = explode("|", $user);
$password = $user[2]; // This way i managed to select the $password
$password = "newpassword";
var_dump($password); //When i click submit it shows the new password but i don't know how to change just the $password in the .txt
/* if ($username == $user[0] && $phone == $user[1]) {
header("Location: index.php?status=userFound");
die();
} else {
header("Location: index.php?status=userNotFound");
die();
} */
}