elmas156 Posted October 22, 2013 Share Posted October 22, 2013 Hello everyone, I have a simple sign in system that has been operational for several months that requires the user to provide a complete email address as a user name and a password. I have had a number of requests by users to have the ability to use the first part of their email address (i.e. testemail @email.com) instead of their full email address. I'm trying to tweak the system to accomodate their requests, but I also want the system to recognize the full email address as well. I'm having some difficulty accomplishing this. Here's how the system is set up and what I've done so far: I have a database with the users' full email (`email`) and password (`pword`). This is how the system has been set up to work only with the full email: <?php $email = $_POST['email']; $pword = md5($_POST['pword']); $q = mysql_query("SELECT * FROM staff WHERE email = '$email' AND pword = '$pword'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); if ($r == 1) { //user is signed in } ?> This is what I've tried to get the system to work with just a username OR with the full email address: <?php $email = $_POST['email']; $pword = md5($_POST['pword']); $my_uname_array = explode("@", $email); $uname = $my_uname_array[0]; $q = mysql_query("SELECT * FROM staff WHERE (email = '$email' OR email LIKE '{$uname}%') AND pword = '$pword'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); if ($r == 1) { //user is signed in } ?> Using this code, the user is still signed in when entering their full email address (testemail@email.com), but not when they only enter their "user name" (testemail). Any ideas on what I might be doing wrong or what I need to do to get it to work properly? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Solution elmas156 Posted October 22, 2013 Author Solution Share Posted October 22, 2013 After continuing to look at my code, I figured out that the problem was not with this snippet of code at all, it was because later in the code, I was using the $email variable to query other information to make everything work. Once I adjusted the code so that I still had the $email variable even if the user only entered a user name, everything worked perfectly. Thanks to all who read my post and attempted to help. Looks like I just didn't look far enough into my code before assuming the problem was with the new code. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.