Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- Binary mode and Regex


typomaniac - 8:12 am on Sep 18, 2011 (gmt 0)


Hi, I'm attempting to do an exact match for profile updating and need to match (case, character for character beginning to end) exactly user input. The code I'm using is:

btw.....all values, table and column names are ficticious and only for demnstration purposes.

if(length($email) >0){
$query = "SELECT email" . "FROM members WHERE binary email REGEXP '^$email$'";
($email) = $dbh->selectrow_array($query);
if(defined($email))
{
print"That email address is already being used";
}


The problem is that no matter what is entered into the form I get the error. If I change the line

if(defined($email)) to if(!defined($email))

I get no error and it doesn't matter if the email address exists or not.

I'm using the same basic syntax for the main login and it seems to be working good.

$query = "select username, password" . " from members where binary username = '$username' and binary password = '$password' limit 1";
($username, $userword) = $dbh->selectrow_array($query);

if((!defined($username)) || (!defined($password)))
{
$loginmsg="Invalid Login Information";
}
elsif((defined($username)) && (defined($password))){
print"You Have Provided Accurate Information";
}


I'm no pro at this, in fact I pretty much got the login syntax from a book I found titled MySQL by Paul DuBois. The syntax for regex was found in the MySql documentation. Is this even a good way of doing this? I'm using perl for this.


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4363957.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com