Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Away to Insert lower case only in your database

    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:

    PHP Code:

    $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

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Any ideas at all? :P
    Last edited by Jon W; 01-14-2008 at 08:25 AM.

  • #3
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    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.
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #4
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ahallicks View Post
    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.
    Last edited by Jon W; 01-14-2008 at 09:37 AM.

  • #5
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Well, according to the php manual 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
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #6
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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:

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

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    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.)
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •