Parse Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmiller
    New Member
    • Sep 2009
    • 1

    Parse Error

    I have a pretty limited knowledge of PHP.

    My scenario is:

    I want one form to have two (2) submit buttons. I want one button to submit an email to a specific address then redirect to a page, and I want the second one to submit to the same email, then redirect to a different page. I've downloaded some code, so I can't take credit for it, but I'm trying to use my basic knowledge to create and IF and ELSE IF. Right now, I'm just trying to get the code to work at all, so I have the form simply submitting the form data to an email address based on the button that was clicked.

    I get the following parse error:

    Parse error: syntax error, unexpected T_ELSE in /home/salamone/public_html/sendeail.php on line 65

    Code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Sendemail Script</title>
    </head>
    <body>
    
    <?php
    
    
    
    
    
    $ip = $_POST['ip'];
    $httpref = $_POST['httpref'];
    $httpagent = $_POST['httpagent'];
    $visitor = $_POST['visitor'];
    $visitormail = $_POST['visitormail'];
    $notes = $_POST['notes'];
    $attn = $_POST['attn'];
    
    
    if (eregi('http:', $notes)) {
    die ("Do NOT try that! ! ");
    }
    if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
    {
    echo "<h2>Use Back - Enter valid e-mail</h2>\n";
    $badinput = "<h2>Feedback was NOT submitted</h2>\n";
    echo $badinput;
    die ("Go back! ! ");
    }
    
    if(empty($visitor) || empty($visitormail) || empty($notes )) {
    echo "<h2>Use Back - fill in all fields</h2>\n";
    die ("Use back! ! ");
    }
    
    if(isset($_POST["sendmail"]) && trim($_POST["sendmail"])!=='') {
    
    $todayis = date("l, F j, Y, g:i a") ;
    
    $attn = $attn ;
    $subject = $attn;
    
    $notes = stripcslashes($notes);
    
    $message = " $todayis [EST] \n
    Attention: $attn \n
    Message: $notes \n
    From: $visitor ($visitormail)\n
    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    ";
    
    $from = "From: $visitormail\r\n";
    
    
    mail("test1@myemail.com", $subject, $message, $from)
    
    
    else if(isset($_POST["sendmail2"]) && trim($_POST["sendmail2"])!=='') {
    $todayis = date("l, F j, Y, g:i a") ;
    
    $attn = $attn ;
    $subject = $attn;
    
    $notes = stripcslashes($notes);
    
    $message = " $todayis [EST] \n
    Attention: $attn \n
    Message: $notes \n
    From: $visitor ($visitormail)\n
    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    ";
    
    $from = "From: $visitormail\r\n";
    
    
    mail("test2@myemail.com", $subject, $message, $from)}
    
    ?>
    </body>
    </html>
    If I am missing something? Thanks in advance!
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Main reason:
    You have not closed your if statement with curly brackets. Should be like:
    Code:
    if (x=1) {
    //do something
    }
    elseif (x=2) {
    //do something else
    }
    else {
    //do yet another thing
    }
    Hope that helps. Welcome to Bytes.
    Last edited by TheServant; Sep 17 '09, 03:30 AM. Reason: Bad advice - corrected by Atli

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey. Welcome to Bytes!

      I see 2 errors there.

      On lines #62 and #85 you are missing the semi-colon (;) to end the line.

      And, before the "else if " on line #65, you are missing the } to close the if preceding it.

      An if structure should look like:
      [code=php]
      if {
      // statementes
      }
      else if {
      // statements
      }[/code]
      Yours is like this:
      [code=php]
      if {
      // statementes
      else if {
      // statements
      }[/code]

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Originally posted by TheServant
        ... and it is not "else if", but "elseif". Big difference.
        Actually, both work in the typical curly-braces structure.
        (See elseif/else if - PHP manual)

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          Originally posted by Atli
          Actually, both work in the typical curly-braces structure.
          (See elseif/else if - PHP manual)
          Point taken. Thanks. And well done with the ";" pick-up ;)

          Comment

          Working...