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
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    proble with or die in contact script

    That is the php part of my contact script
    Code:
    <?php
    
    $alertall = "you need to fill in all fields";
    
    if ($_POST['name'] == "")	
    echo"<? $alertall ?>";	 
    
    if ($_POST['email'] == "")	
    echo"<? $alertall ?>";	 
    
    if ($_POST['title'] == "")	
    echo"<? $alertall ?>";
    	 
    if ($_POST['text'] == "")	
    echo"<? $alertall ?>";
    
    else {
      mail ('kontakt@mywebsite.com', '$title', '$text');
      echo"it was send correctly, go back on <a href=\"http://www.mywebsite.com\">main page</a><br /> or to <a href=\"http://www.mywebsite.com\">cobntact formular</a>";
     } or die { "Impossible to send a formular"; }	
    
    
    ?>
    The problem is that it shows an error
    T_LOGICAL_OR
    ? What can be wrong?

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    try this;

    PHP Code:

    $alertall 
    "you need to fill in all fields";

    if (
    $_POST['name'] == "") echo $alertall;     

    if (
    $_POST['email'] == "") echo $alertall;     

    if (
    $_POST['title'] == "") echo $alertall;
         
    if (
    $_POST['text'] == "") echo $alertall;

    if(
    $alertall <> ""){
        echo 
    $alertall;
    } else {
        
    mail ('kontakt@mywebsite.com''$title''$text') or die ("Impossible to send a formular");    

    Last edited by angst; 02-03-2010 at 04:00 PM.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The problem is that it shows an error
    T_LOGICAL_OR
    ? What can be wrong?
    What do you expect for that or die() part?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I think the curly braces are out of whack in that, angst.

    @Abdem: else..or die() won't work. An else is the final condition of an if/else structure, so you can't OR anything with it. Perhaps you mean to use an elseif instead?
    Are you a Help Vampire?

  • #5
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    If somebody try to contact with using that formular and it is impossible to show him a message that it's impossible

    @up I didn't see your post
    Last edited by Adbem; 02-03-2010 at 04:03 PM.

  • #6
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    yah your right, I missed one, but also noticed some more issues with his code. updated*

  • #7
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    I'm not sure why you want to echo out the error message every time there's an error. If no fields are set you are going to get the error message sent 4 times. Try something like this instead
    PHP Code:
    $fields exlpode(',''name,email,title,text');
    $error false;

    foreach(
    $fields as &$v) {
        if(!isset(
    $_POST[$v]) || trim($_POST[$v] == '')){
            
    $error true;
            break;
        }else{
            
    $v trim($v);
        }
    }

    if(
    $error) {
        die(
    'You need to fill in all fields');
    }else{
        if(!
    mail('kontact@mywebsite.com'$title$text)) {
            die(
    'Impossible to send a formular');
        }else{
            echo 
    'it was send correctly, go back on <a href="http://www.mywebsite.com">main page</a><br /> or to <a href="http://www.mywebsite.com">cobntact formular</a>';
        }

    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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