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 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If statment not working

    When I enter the username 700lbGorilla if goes to the "6-20 character statement" statement. Not understanding why, becase I've tested the preg_match statement before and it worked. Now that I have it in a different if statement it isn't working.

    PHP Code:
    if(preg_match('/^[a-zA-Z0-9]\w*[a-zA-Z0-9]$/'$_POST['uname'])) 
        {
            if(
    strlen($_POST['uname'] > 5) && strlen($_POST['uname'] < 21)) {
                
    $u $_POST['uname'];
            } else {
                
    $u FALSE;
                echo 
    '<p><font color="red">Username needs to be 6-20        characters.</font></p>';
            } 
        } else {
            
    $u FALSE;
            echo 
    '<p><font color="red">Username is not in valid format.</font></p>';
        } 

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    you seem to be missing a few brackets there... not sure it should even parse but...

    PHP Code:
    if(strlen($_POST['uname'] > 5) && strlen($_POST['uname'] < 21)) { 
    should be
    PHP Code:
    if((strlen($_POST['uname']) > 5) && (strlen($_POST['uname']) < 21)) { 

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh... thank you, didn't know I needed those ones. Another quick question has nothing to do with this topic. If you insert something into a DB that doesn't have a value, is it like inserting nothing?

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    that depends how you insert it, if you insert

    as $emptyvariable then I think it would count as NULL whereas '$emptyvariable' would be a zero length string I believe.

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It depends as well on your database setup. If your table is set up, and the column has "NOT NULL" set, the empty value (whether it be NULL or an empty string ""), will be inserted into the database as an empty string. If the column is set to NULL, then it will depend on your query.

    A query to insert a NULL value:
    Code:
    INSERT INTO table VALUES ( 'value 1', NULL )
    So if you are inserting an empty string with quotes around it, I think it will still count as as being a value and just insert the empty string (even the column is a NULL column)

    By the way, if you are wondering, NULL columns have a use when it comes to counting. So say the field "value" in my table has some null entries, if I run
    Code:
    SELECT COUNT(value) FROM table
    It will only return a count of the non-null entries, null entries are ignored in this case.


  •  

    Posting Permissions

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