Jump to content

Help with sign in system


elmas156
Go to solution Solved by elmas156,

Recommended Posts

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.

 

 

Link to comment
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.