PDA

Click to See Complete Forum and Search --> : PHP/MySQL question...


websurfer907
Oct 21st, 2000, 02:48 PM
Hello!

I just started learning PHP and MySQL about a week ago, so this is probably a stupid question :rolleyes:, but anyway...

I am using this code:




$Result = mysql_query("SELECT UserName, Password, LastLogin FROM Members WHERE UserName = '" . $username . "'");


and it works, but when somebody enters their username and it doesn't have the same case as when they registered (say, websurfer907 instead of Websurfer907) it won't work. UserName is a varchar, and every MySQL site I've seen says that varchar is case-insesitive. What am I doing wrong? I also tried this:



$Result = mysql_query("SELECT UserName, Password, LastLogin FROM Members WHERE STRCMP('" . $username . "', UserName) = 0");


and the same thing happened. Help!

Oct 21st, 2000, 03:17 PM
http://www.php.net/manual/html/function.strtolower.html


try doing this



$Result = mysql_query("SELECT UserName, Password, LastLogin FROM Members WHERE strtolower(UserName) = '" . strtolower($username) . "'");




I am not absolutely sure if strtolower will work with UserName (not a PHP variable, it's a mysql variable.. or whatever)

just try it!!! :p :rolleyes:

websurfer907
Oct 21st, 2000, 03:27 PM
It didn't work. It gave me this error:

Warning: 0 is not a MySQL result index in /usr/home/progstuf/login.php on line 31

any other ideas? maybe there is a MySQL version of strtolower?

websurfer907
Oct 21st, 2000, 03:31 PM
Ah ha! Found it.

http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#IDX734

Going to try it now

websurfer907
Oct 21st, 2000, 03:35 PM
It didn't work for some reason... this is what I tried:


$Result = mysql_query("SELECT UserName, Password, LastLogin FROM Members WHERE LCASE(UserName) = '" . strtolower($username) . "'");


Any ideas?

websurfer907
Oct 21st, 2000, 03:42 PM
Never mind.

I got it to work. I had some code further down that checked if the usernames were the same again but it didn't use strtolower. Oops. :rolleyes: