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

    if statement question

    Alright, well here in my script I'm trying to check and see if a value it filled and if the values both match. For some reason I'm getting a error message with this line of code though. (I thought it was a pretty sample line of script)

    PHP Code:
    <?php if(!empty($_POST['Password'])) && ($_POST['Comfirmed_password']) == ($_POST['Password']) { echo($_POST['Comfirmed_password']); } else { echo ''; } ?>
    By the way this is going inside of a value you tag.

    Thanks for the help

    And as a side question, which I know is going to be one of the next questions that I ask.... How can I make a Random key for the User name? I saw it in some login script that it creates a random key, but not to sure how to make the function or whatever to make the random key. Heres the site that I was looking off of: http://www.roscripts.com/PHP_login_script-143.html

    Jon W
    Last edited by Jon W; 01-06-2008 at 09:23 PM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Jon W View Post
    Alright, well here in my script I'm trying to check and see if a value it filled and if the values both match. For some reason I'm getting a error message with this line of code though. (I thought it was a pretty sample line of script)

    PHP Code:
    <?php if(!empty($_POST['Password'])) && ($_POST['Comfirmed_password']) == ($_POST['Password']) { echo($_POST['Comfirmed_password']); } else { echo ''; } ?>
    By the way this is going inside of a value you tag.

    Thanks for the help
    Jon W
    PHP Code:
    <?php
    if(isset($_POST['Password']) &&
       isset(
    $_POST['Comfirmed_password']) &&
       !empty(
    $_POST['Password'])) &&
       !empty(
    $_POST['Comfirmed_password']) &&
       
    $_POST['Comfirmed_password'] === $_POST['Password']) {
         echo(
    $_POST['Comfirmed_password']);
    } else {
         echo 
    'no match';
    }
    ?>
    - note the === instead of == and filled message in else branch

    probably empty(...) is useless, but check the php manual, I can't remember now and I have not time to check myself, when empty return false? ( sure if is '', but when x is unset, empty(x) is true?) AFAIK if a value in a form is not filled POST for that value is unset, check this too.

    best regards
    Last edited by oesxyl; 01-06-2008 at 09:36 PM.

  • #3
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    i think someone mentioned that it's good to use strlen() or similar in these situations. then you can limit minimum to let's say 4 characters.

    i'm not sure is this what you asked, but it can be usefull anyway

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by oesxyl View Post
    probably empty(...) is useless, but check the php manual, I can't remember now and I have not time to check myself, when empty return false? ( sure if is '', but when x is unset, empty(x) is true?)
    Any value that equals false('', NULL, 0) or if it's not set will return true. So as long as you aren't expecting a 0 for your form input it should work fine.
    Quote Originally Posted by oesxyl View Post
    AFAIK if a value in a form is not filled POST for that value is unset, check this too.
    Nope, even if it's blank it will still be set in the $_POST array.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Inigoesdr View Post
    Any value that equals false('', NULL, 0) or if it's not set will return true. So as long as you aren't expecting a 0 for your form input it should work fine.

    Nope, even if it's blank it will still be set in the $_POST array.
    do you mean blank as space+, not "not filled with anything", isn't it?
    in last case, print_r($_POST), echo a [field name] => '' item?

    best regards.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by oesxyl View Post
    do you mean blank as space+, not "not filled with anything", isn't it?
    in last case, print_r($_POST), echo a [field name] => '' item?
    If you have a form such as this:
    Code:
    <form action="test.php" method="post">
    <input type="text" name="test" />
    <input type="submit" />
    </form>
    And you submit it without anything in the text field, the $_POST array will be array('test' => '');

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Inigoesdr View Post
    If you have a form such as this:
    Code:
    <form action="test.php" method="post">
    <input type="text" name="test" />
    <input type="submit" />
    </form>
    And you submit it without anything in the text field, the $_POST array will be array('test' => '');
    thanks, , I hope you don't west your time to test this, a simple yes was enough, . Usualy when I'm not sure about something I test myself, I ask only because I have not enough time for this and I was curios about the result even is not important for me in this moment.

    best regards


  •  

    Posting Permissions

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