This is what happens when you copy code for your project but you don't understand the code or it's inner workings :)
1.In your login page, create an html form with a POST method.
2. In the form element, create your username and password text elements.
3. After these, add a submit button.
Your reference in your form POST method will be your php page name that houses your above code.
You can also submit to this same page after validating all inputs vi the POST method.
If data is validated, refer to your next page. Check out THIS
link for a tutorial.