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 ([email protected]), 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. Link to comment https://forums.phpfreaks.com/topic/283191-help-with-sign-in-system/ Share on other sites More sharing options...
elmas156 Posted October 22, 2013 Author 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! Link to comment https://forums.phpfreaks.com/topic/283191-help-with-sign-in-system/#findComment-1454968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.