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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to write it properly?

    Can you tell me how to write it properly ?
    Code:
    if(isset($_POST['button'])) && ($_POST['form'] = !null)){
    echo 'choose something';
    }
    else{
    echo 'great choice!';
    }

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    PHP Code:
    if(isset($_POST['button'])) && ($_POST['form'] != null)){
    echo 
    'choose something';
    }
    else{
    echo 
    'great choice!';

    or

    PHP Code:
    if(!empty(@$_POST['form'])){
    echo 
    'choose something';
    }
    else{
    echo 
    'great choice!';

    The @ turns off error reporting for getting the function/variable after so avoids the need to use isset.
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by timgolding View Post
    PHP Code:
    if(isset($_POST['button'])) && ($_POST['form'] != null)){
    echo 
    'choose something';
    }
    else{
    echo 
    'great choice!';

    or

    PHP Code:
    if(!empty(@$_POST['form'])){
    echo 
    'choose something';
    }
    else{
    echo 
    'great choice!';

    The @ turns off error reporting for getting the function/variable after so avoids the need to use isset.
    first one
    Parse error: syntax error, unexpected T_BOOLEAN_AND
    second one
    Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '$'

  • #4
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Sorry i didn't test them let me fix that.
    You can not say you know how to do something, until you can teach it to someone else.

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Sorry empty seems to check if it exsists and is empty all in one hit.

    PHP Code:
    <?php
    if(empty($_POST['form'])){
    echo 
    'choose something';
    }
    else{
    echo 
    'great choice!';
    }
    ?>
    However you might want to use

    PHP Code:
    <?php

    if(!isset($_POST['button']) && $_POST['form'] == ""){
    echo 
    'choose something';
    }
    else{
    echo 
    'great choice!';
    }  
    ?>
    As empty returns true if $_POST["form"] is set to 0 for instance
    You can not say you know how to do something, until you can teach it to someone else.

  • #6
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you!
    a hug to you

  • #7
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by anna90 View Post
    thank you!
    a hug to you
    thanks
    You can not say you know how to do something, until you can teach it to someone else.

  • #8
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    If by how to write it properly you meant why doesn't my code work it's because you forgot a left paren right after the if.


  •  

    Tags for this Thread

    Posting Permissions

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