How to Login with Username or Email Id using PHP & MYSQL

4 Responses

  1. Dave says:

    Why so complicated? You don’t need to create a function to determine if the user is logging in with an email address or a username. Just let MySQL handle it – here is an example:

    $name = $_POST[‘username’]; # userid can be an email address or a username
    $pass = md5($_POST[‘password’]); # Password

    $query = mysql_query(“SELECT * FROM `users` WHERE ‘$name’ IN (username, email) AND `password` = ‘$pass'”);

    Also, your example is vulnerable to SQL injection… At that point, you should start using MySQLi or PDO + prepared statements. Don’t use this example in a production environment…

  2. Sumit says:

    Script is not working kindly provide the database

  3. Sagar SN says:

    Thanks Karthikeyan and Dave that helped me a lot, i followed the same code for login using email/phone

Leave a Reply

Your email address will not be published. Required fields are marked *