Search code examples
phpuser-accounts

Login in to website with php and MySQL


On my website so far a user can add their username, password and email to a MySQL database through php. I want to now let a user type those same credentials (username and password) into forms and then run a php script and check if the Username and passwords are in the database. How would write this script?


Solution

  • Make a php function that gets what the user enters, then select them from your user table. If it returns something, say its is already in the database.

    Example:

    SELECT uname, pw FROM users WHERE uname="userNameInput" AND pw="userPwInput"; 
    

    if this returns a row, it already is in the db.

    You can then run this function on your choice of hitting a button or in every key stroke by calling the function with ajax.