Bendude14 Posted July 15, 2008 Share Posted July 15, 2008 What i would like to achieve is that if someone registers on my site with the username Ryan then they will still be able to login even if they try to login with the username RYAN or RaYn etc. I know i could use strtolower, but towards the top of the page where it displays the current user's name i would like it to display in the same format as it was when they registered. so if they registered as ryaN it would always say ryaN even if they logged in using RYAN or Ryan. just a pointer in the right direction would be great Thanks Ben Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/ Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 Store the username as it is, just while checking convert it to lowercase "SELECT * from `user` WHERE LOWER(`username`) = '".strtolower($username)."'" Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-590353 Share on other sites More sharing options...
Bendude14 Posted July 15, 2008 Author Share Posted July 15, 2008 Thanks ill give it a try Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-590357 Share on other sites More sharing options...
Bendude14 Posted July 15, 2008 Author Share Posted July 15, 2008 That does not seem to let people login if you put all capital letters to login or a variant from what was entered into the DB I was using this before <?php $sql = "SELECT pwd FROM users WHERE username = '$username'"; ?> And i changed it to this after looking at your code <?php $sql = "SELECT pwd FROM users WHERE LOWER ('username') = '".strtolower($username)."'"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-590366 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 <?php $sql = "SELECT pwd FROM users WHERE LOWER (`username`) = '".strtolower($username)."'"; ?> Field names should not be in single quotes, surroung them with bck ticks..try and let me know Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-590378 Share on other sites More sharing options...
Wolphie Posted July 15, 2008 Share Posted July 15, 2008 I've never had any problem writing and retreiving data from the database in any character case. Have you tried just writing a value to the database using different cases throughout and then tried validating it using lower case / upper case? <?php $sql = "SELECT pwd FROM users WHERE LOWER (`username`) = '".strtolower($username)."'"; ?> Field names should not be in single quotes, surroung them with bck ticks..try and let me know A back tick is just another form of a quote, it doesn't matter what you surround them in, it's strictly for clarity and easy reading. Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-590379 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 What i would like to achieve is that if someone registers on my site with the username Ryan then they will still be able to login even if they try to login with the username RYAN or RaYn etc. when they login and you confirm their password also pull back their name.. and use the for formatting from that.. as it sounds like your using the name they entered during login.. $username = "RyAn"; $sql = "SELECT username, pwd FROM users WHERE username = '$username'"; $username = $row['username']; should be fine Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-590388 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 m not sure...in a query data surrounded in a single quote would be treated as a string... select 'username' from user; will return the string 'username' where as select `username` from user; will return the actual value of the column Bendude14 , please try query which i posted earlier. hope it is clear... Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-590393 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 A back tick is just another form of a quote, it doesn't matter what you surround them in, it's strictly for clarity and easy reading. Wrong... quotes are for strings, back ticks are for quoting identifiers, ie fields/ tables etc.. so samshel is correct. Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-590419 Share on other sites More sharing options...
Bendude14 Posted July 16, 2008 Author Share Posted July 16, 2008 Ok first of all i tried this from samshel but i get the error message that Function LOWER does no exist. <?php <?php $sql = "SELECT pwd FROM users WHERE LOWER (`username`) = '".strtolower($username)."'"; ?> ?> so i tried <?php $username = "RyAn"; $sql = "SELECT username, pwd FROM users WHERE username = '$username'"; $username = $row['username']; ?> And what happens here is that you can only login if the username is typed exactly as it was on first login. Thanks for all the help so far Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-591169 Share on other sites More sharing options...
MadTechie Posted July 16, 2008 Share Posted July 16, 2008 erm.. LOWER does exist! try this.. <?php $username = "RyAn"; $sql = "SELECT username, pwd FROM users WHERE LOWER(username) = LOWER('$username')"; $username = $row['username']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-591180 Share on other sites More sharing options...
Bendude14 Posted July 16, 2008 Author Share Posted July 16, 2008 erm.. LOWER does exist! LOL so it does ... Thanks everything works fine now. Great help MadTechie and Samshel Quote Link to comment https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/#findComment-591184 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.