I don't really see anything that's wrong.
Try adding more output to the login() function, which is currently very compact. Store the generated SQL query in a variable, and print it on the screen before running it. Store the returned COUNT(*) value in a variable, and print that too on the screen. Then you'll see what's going on.
I'd suggest to construct the new contents of the file and store it with a temporary filename, and only switch it over to the real name when it's finished.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.