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 6 of 6

Thread: if else

  1. #1
    New Coder
    Join Date
    Jul 2003
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question if else

    why if i submit my form blank i have message like: been mailed to roma?

    PHP Code:
    <?
    if ($button==roma){
        
    $to="x@x.net";
    }else{
        
    $to="y@y.net";
    }
    $message stripslashes($_POST['message']);
    if (isset(
    $message)){
         
    $check mail($to,"",$message,"From: _@{$_SERVER['REMOTE_ADDR']}\r\n");
    if(
    $check) {
         echo 
    $message.'<br/>been mailed to '.$button;
    }else{
         echo 
    '<div class=error>unable to send sms!</div>';
    }
    }else{
    echo 
    '<div class=error>xxxx happens</div>';
    }
    ?>

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because you can send blank emails and the $check is set to 1 (or true?) whenever the mail was successfully sent. The next line, you check if $check evaluates to "true", and when then mail has been sent, you print the $message variable, but it's blank, and so you only get " been sent to roma".
    De gustibus non est disputandum.

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why don't you try?:
    PHP Code:
    if (!empty($message)) { 

  • #4
    New Coder
    Join Date
    Jul 2003
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    aha!

    isset() isn't appropriate in my case because it returns TRUE even if it's empty, isn't it? but if i use empty(), then i can do more precise check. am i right?
    so the code would be:

    PHP Code:
    <?
    if ($button==roma){
        
    $to="x@x.net";
    }else{
        
    $to="y@y..net";
    }
    $message stripslashes($_POST['message']);
    if (!empty(
    $message)){
         
    $check mail($to,"",$message,"From: _@{$_SERVER['REMOTE_ADDR']}\r\n");
    if(
    $check) {
         echo 
    "<div class=bdr>$message. <br/>been mailed to .$to</div>";
    }else{
         echo 
    '<div class=error>unable to send sms!</div>';
    }
    }else{
    echo 
    '<div class=error>**** happens</div>';
    }
    ?>

  • #5
    New Coder
    Join Date
    Jul 2003
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and now if i leave the form empty i have 'xxxx happens'

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    er yeah, thats what you should get. Did you read the code at all?
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)


  •  

    Posting Permissions

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