...

View Full Version : Away to Insert lower case only in your database



Jon W
01-14-2008, 08:06 AM
How would you be able to insert only lower case world in your database. I thought that I could just use the strtolower function and that would do the stick. But that didn't seem to work. This is what I used here:




$email = strtolower(mysql_real_escape_string($_POST['email']));

$query = mysql_query("SELECT id, username, email FROM users WHERE email = '$email'") or die('Database error: ' .mysql_error());



Notices the 'strtolower' function before the mysql_real_escape_string. But that didn't. This page that I'm using it for it actually a password recovery page. And I noticed if I don't type in exactly how it is in the database it will come back and tell me that the email is invalid. Maybe there is other ways to do this, but I thought the best way was to make everything that gets inserted into the database (such as the email) would be lower case only. And so when a person goes to type in the Email address doesn't matter if the email address is typed in all caps or however the they type it, it still find it in the database. If you got any suggest or any ideas, that would be great.

Thanks
Jon W

Jon W
01-14-2008, 08:23 AM
Any ideas at all? :P

ahallicks
01-14-2008, 09:02 AM
It would help if you posted this in the correct forum for a start. Do you not encrypt your passwords into the database? If not, do your members know that you can see their passwords? Use some form of encryption, then rather than having a password recovery page if you use an encryption that can't be decypted, simply have the member choose another password.

Jon W
01-14-2008, 09:32 AM
It would help if you posted this in the correct forum for a start. Do you not encrypt your passwords into the database? If not, do your members know that you can see their passwords? Use some form of encryption, then rather than having a password recovery page if you use an encryption that can't be decypted, simply have the member choose another password.

Oops, I'm very sorry. I didn't notices that I was in the 'HTML - CSS' forum. Next time I'll be sure to pay more attention to that. If a Moderator could move my post to the PHP forum that would be great. Once again, sorry, didn't notice that I was in the wrong forum.

A reply back to ahallicks:

Yes I do encrypy the passwords. And I don't have members. I'm no where near knowledge enough in PHP to even think about having members on my site. This password recovery page does NOT send the password. Its samply a email that gets sent to the user to verfiy that user with the email address is the actual owner of the account. If so, then only will that person be able to change the password for that account.

ahallicks
01-14-2008, 01:03 PM
Well, according to the php manual strtolower (http://uk.php.net/strtolower) should be correct. Just make sure you are passing the right variables and print out the output to screen to see if it is working there first

arnyinc
01-14-2008, 06:50 PM
First you would need to make sure everything in your database is already lowercase. Right now you are converting everything to lowercase when you are SELECTing, but if the data in your database has any capital letters, then your SELECT won't work.

You can create a trigger in mysql to automatically convert all data to lower/upper case:



CREATE TRIGGER trgConvertToLowercase BEFORE INSERT ON tblYourTable FOR EACH ROW BEGIN SET NEW.email=LOWER(NEW.email);

CFMaBiSmAd
01-14-2008, 07:21 PM
Post your table definition.

In general, database queries are not case sensitive, unless your column type forces a binary, character by character match.

You could also have some white-space before or after what was entered that needs to be trimmed (either on what is already in the database or what is getting entered and compared in the WHERE clause.)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum