The most immediate problem is an error in one of the sql queries. You are actually fortunate that an update query isn’t being executed, because it would mess up the saved hashed passwords (do NOT retrieve the hashed password values from the database and output them as a form field value.)
Instead of using out of date or die(…) statements for error handling, use exceptions for database statement errors and in most cases let php catch and handle the exception where it will use its error related settings to control what happens with the actual error information (database errors will get displayed/logged the same as php errors.) The exception to this rule is when inserting/updating user submitted data and you need to handle duplicate or out of range values. In this case, your code would catch the exception, detect if the query error number is one that your code can handle and recover from, and set up a message telling the user what exactly was wrong with the submitted data. If the error number is not one that your code is designed to handle, you would re-throw the exception and let php handle it. Detecting duplicate user submitted data is something you need to do, but first get your code to work without this feature.
To enable exceptions for errors for the mysqli extension, add the following single line of code before the point where you make the database connection, then remove all the database error handling logic you have now -
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
Next, there are issues with almost everything this code is doing, that are either non-secure, unnecessary, wasteful, or provide a bad user experience. If I/others have time we will post list(s) of problems and good programming practices to use…