#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0

    Problem with php ( if and )


    Hello , i am a beginner in php but i've already wrote my own registration script with mysql etc :P kinda working on it now.

    So the problem:

    PHP Code:
    if($_POST['email']=="" && (strlen($_POST['email'] <=10))){   die("Email is incorrect");   } 
    it doesnt recognize strlen somehow,
    what im trying to do is connecting two ifs

    Trying to make 1 if instead of 2, example:
    PHP Code:
    if($_POST['email']==""){   die("Email is incorrect");   }
    if (
    strlen($_POST['email'] <=10))){   die("Email is incorrect");   } 
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0
    agh never mind i already have a solution
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    You probably want to use || instead of &&, although the first condition is actually completely redundant - if $_POST['email'] == "" then strlen($_POST['email']) can't possible by greater than 10.

    Validating an E-Mail address using a minimum length of 10 seems kind of arbitrary. There are valid E-Mail addresses under 10 characters long. You might want to look at the filter_var function instead or use a basic regular expression like ^[^@]+@.+$
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0
    Originally Posted by E-Oreo
    You probably want to use || instead of &&, although the first condition is actually completely redundant - if $_POST['email'] == "" then strlen($_POST['email']) can't possible by greater than 10.

    Validating an E-Mail address using a minimum length of 10 seems kind of arbitrary. There are valid E-Mail addresses under 10 characters long. You might want to look at the filter_var function instead or use a basic regular expression like ^[^@]+@.+$
    I've read all kind of stuff about filter ,
    now i tried to use :
    $email = $_POST['email'];
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    die("Email is not valid");
    }

    But that doesn't work well , you can use email without mail ending for example : example@example it will count it as valid even tho it doesn't have .com at the end
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    example@example is technically a valid E-Mail, a host name doesn't actually have to end in .anything, it's just that all internet domains do. If having a working E-Mail address is important, validate it by sending an E-Mail to it and requiring the user to click on a link inside it acknowledging receipt.

    Also strlen > 10 would validate example@example too.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    12
    Rep Power
    0
    Yep true , you're right
    now i got another question , since im newbie in that BUT i try to do everything atleast a little secure right from the starts ,
    for example while writing registration script at first it was registering blank or same usernames and all but i fixed all that of course and now it runs perfectly , All though im curious if its normal that i user die option many times
    for example
    If username contains less than 0 characters ,
    die - Username incorrect.

    And i kinda do that for all the important fields, should i use other tag instead of die ? coz i belive if i'll build a little larger system and someone will try to register and type something wrong all the scripp will receive command die and even things non related to registration will be forced to stop , or im wrong and using die option alot is normal ?

IMN logo majestic logo threadwatch logo seochat tools logo