Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-08-2003, 06:02 PM   #1 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
php function to change to lower case

I found a "bug" in my register script......

when it checks to see if the username exists, if the user enters Trevor and trevor already exists, it still makes the account Trevor, so there is a Trevor and trevor.

so I need to change $username to lowercase before it checks the database.

is there a function for this?

thanks,

Trevor
trevor is offline   Reply With Quote
Old 02-08-2003, 06:17 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
PHP Code:
<?
$username
="trevor";

$result=mysql_query("select * from users where username='$username'");

$num=mysql_numrows($result);

if(
$num 0) {
  echo 
"sorry, that username already exists.";
}
else {
  
// do registration here
}
?>
that query should not be case sensitive .. so if it returns any more than 0 results, .. there is a 'Trevor' or 'trevor' already existing in your system.
sde is offline   Reply With Quote
Old 02-08-2003, 06:25 PM   #3 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
n/m

found it

$username = strtolower($username);
trevor is offline   Reply With Quote
Old 02-08-2003, 06:27 PM   #4 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
it is case sensative for some reason, thats how I had it, i didn't think it was case sensative but it is.
trevor is offline   Reply With Quote
Old 02-09-2003, 04:40 PM   #5 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
Quote:
Originally posted by sde
that query should not be case sensitive .. so if it returns any more than 0 results, .. there is a 'Trevor' or 'trevor' already existing in your system.
ansi sql is not case sensitive*. that is, the operators are not. so:

"select * from users"
is the same as:
"SELECT * From UsErs"

* mysql, as usual, breaks the standard and enforces case sensitivity on object names (ie, tables and columns).

however, data comparisons certainly are case sensitive. if you want to find out if you have any instances of "trevor" in your user db, regardless of case, you will have to do this:

PHP Code:
<?
  $sql 
"select * from users where LOWER(name)='".strtolower($username)."'";
?>
Quote:
PHP Code:
$result=mysql_query("select * from users where username='$username'"); 
the above code is wrong, because if 'TREvor' was already in the database, it would not find it.

of course, you'd not use the sql LOWER() function in high performance situations, since it has to lowercase every username in the database for comparison. but once you've reached that point, i'm sure you'd know better already.
joe_bruin is offline   Reply With Quote
Old 02-10-2003, 02:58 PM   #6 (permalink)
Phytoporg
Registered User
 
Join Date: Feb 2003
Location: Ridgewood, NJ
Posts: 1
Phytoporg is on a distinguished road
Send a message via AIM to Phytoporg Send a message via Yahoo to Phytoporg
I typically would do something like this in a situation where case needs to be ignored:

$results = mysql_query ("select * from users where username like '$username'");
Phytoporg is offline   Reply With Quote
Old 02-10-2003, 03:17 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
http://www.mysql.com/doc/en/Case_sensitivity.html

this may help, although not much there.
sde is offline   Reply With Quote
Old 02-11-2003, 07:12 AM   #8 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
using 'like' isnt good, it can return incorrect results.

i do something like this.

select foo from bar where upper(eke) = upper('$eke');
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 02-11-2003, 02:45 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
matt is smart, he taught me everything i know.
sde is offline   Reply With Quote
Old 02-11-2003, 08:27 PM   #10 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
Quote:
Originally posted by sde
matt is smart, he taught me everything i know.
yeah right, im stupid.
__________________


Urban Clothing
Admin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
c simple question problem with switch case if13121 Standard C, C++ 1 10-24-2004 09:43 PM
Help for another program Androto Standard C, C++ 54 10-15-2004 07:21 AM
Upper case string to lower case gamehead200 Standard C, C++ 12 10-15-2004 03:24 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM
is there an alphanumeric php function? sde PHP 2 12-17-2002 02:21 PM


All times are GMT -8. The time now is 07:13 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting