Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/114813-solved-preserve-username-formatting/
Share on other sites

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)."'";
?>

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.

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

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...

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.

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

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.