www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Unexpected $end...

  1. #1
    Join Date
    Jun 2006
    Location
    Doncaster
    Posts
    78

    resolved [RESOLVED] Unexpected $end...

    Hi,
    I'm getting an error:
    Parse error: syntax error, unexpected $end in C:\wamp\www\milton\contact.php on line 99
    from the following code:
    PHP Code:
    <?php
    session_start
    ();
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact Milton Players</title>
    <style type="text/css">
      .label{
        text-align:right;
      }
     
    </style>
    <link href="m4.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
    <?php
      $to
    ='test@holtworth.co.uk';
      
    $messageSubject='Message subject';
      
    $confirmationSubject='Confirmation message subject';
      
    $confirmationBody="Confirmation message body";
      
    $email='';
      
    $body='';
      
    $displayForm=true;
      if (
    $_POST){
        
    $email=stripslashes($_POST['email']);
        
    $body=stripslashes($_POST['body']);
        
    // validate e-mail address
        
    $valid=eregi('^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$',$email);
        
    $crack=eregi("(\r|\n)(to:|from:|cc:|bcc:)",$body);
        if (
    $email && $body && $valid && !$crack){
          if (
    mail($to,$messageSubject,$body,'From: '.$email."\r\n")
              && 
    mail($email,$confirmationSubject,$confirmationBody.$body,'From: '.$to."\r\n")){
            
    $displayForm=false;
    ?>
    <p>
      Your message was successfully sent.
      In addition, a confirmation copy was sent to your e-mail address.
      Your message is shown below.
    </p>
    <?php
            
    echo '<p>'.htmlspecialchars($body).'</p>';
          }else{ 
    // the messages could not be sent
    ?>
    <p>
      Something went wrong when the server tried to send your message.
      This is usually due to a server error, and is probably not your fault.
      We apologise for any inconvenience caused.
    </p>
    <?php
          
    }
        }else if (
    $crack){ // cracking attempt
    ?>
    <p><strong>
      Your message contained e-mail headers within the message body.
      This seems to be a cracking attempt and the message has not been sent.
    </strong></p>
    <?php
        
    }else{ // form not complete
    ?>
    <p><strong>
      Your message could not be sent.
      You must include both a valid e-mail address and a message.
    </strong></p>
    <?php
        
    }
      }
      if (
    $displayForm){
    ?>
    <form action="contact.php" method="post">
      <table>
        <tr>
          <td class="label"><label for="email">Your e-mail address</label></td>
          <td>
            <input type="text" name="email" id="email" value="<?php echo htmlspecialchars($email); ?>" size="30">
            (a confirmation e-mail will be sent to this address)
          </td>
        </tr>
        <tr>
          <td class="label"><label for="body">Your message</label></td>
          <td><textarea name="body" id="body" cols="70" rows="5">
            <?php echo htmlspecialchars($body); ?>
          </textarea></td>
        </tr>
        <tr><td class="label"><label for="submit">Send:</label></td><td id="submit"><button type="submit">Send message</button></td></tr>
      </table>
    </form>

    Cancel and return to 
    <?php
    if (isset($_SESSION[first_name]))
    echo 
    "<a href=\"member.php\">your page</a>";
    else 
    echo 
    "<a href=\"index.php\">the home page</a>";
    ?>.
    </body>
    </html>
    Tried eliminating <?'s - no joy. Any ideas?

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    Hint: when you get this error, take a good long look at your curly brackets.


    Hint #2 - Where's the closing } for

    PHP Code:
     if($displayForm) { 



    EDIT: If you still get the same error after you've fixed this, don't think that the fix didn't help the situation, it just means that one or other of your if-else statements that you declared up top in your document isn't closed.

  3. #3
    Join Date
    Jun 2006
    Location
    Doncaster
    Posts
    78
    Yes, yes - works on both counts.
    It turns out the curly bracket should have been at the end - this is (and my hands are up) not my script, and I broke it when editing it. For the record it should look like:
    PHP Code:
    <?php
    session_start
    ();
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact Milton Players</title>
    <style type="text/css">
      .label{
        text-align:right;
      }
     
    </style>
    <link href="m4.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
    <?php
      $to
    ='test@holtworth.co.uk';
      
    $messageSubject='Message subject';
      
    $confirmationSubject='Confirmation message subject';
      
    $confirmationBody="Confirmation message body";
      
    $email='';
      
    $body='';
      
    $displayForm=true;
      if (
    $_POST){
        
    $email=stripslashes($_POST['email']);
        
    $body=stripslashes($_POST['body']);
        
    // validate e-mail address
        
    $valid=eregi('^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$',$email);
        
    $crack=eregi("(\r|\n)(to:|from:|cc:|bcc:)",$body);
        if (
    $email && $body && $valid && !$crack){
          if (
    mail($to,$messageSubject,$body,'From: '.$email."\r\n")
              && 
    mail($email,$confirmationSubject,$confirmationBody.$body,'From: '.$to."\r\n")){
            
    $displayForm=false;
    ?>
    <p>
      Your message was successfully sent.
      In addition, a confirmation copy was sent to your e-mail address.
      Your message is shown below.
    </p>
    <?php
            
    echo '<p>'.htmlspecialchars($body).'</p>';
          }else{ 
    // the messages could not be sent
    ?>
    <p>
      Something went wrong when the server tried to send your message.
      This is usually due to a server error, and is probably not your fault.
      We apologise for any inconvenience caused.
    </p>
    <?php
          
    }
        }else if (
    $crack){ // cracking attempt
    ?>
    <p><strong>
      Your message contained e-mail headers within the message body.
      This seems to be a cracking attempt and the message has not been sent.
    </strong></p>
    <?php
        
    }else{ // form not complete
    ?>
    <p><strong>
      Your message could not be sent.
      You must include both a valid e-mail address and a message.
    </strong></p>
    <?php
        
    }
      }
      if (
    $displayForm){
    ?>
    <form action="contact.php" method="post">
      <table>
        <tr>
          <td class="label"><label for="email">Your e-mail address</label></td>
          <td>
            <input type="text" name="email" id="email" value="<?php echo htmlspecialchars($email); ?>" size="30">
            (a confirmation e-mail will be sent to this address)
          </td>
        </tr>
        <tr>
          <td class="label"><label for="body">Your message</label></td>
          <td><textarea name="body" id="body" cols="70" rows="5">
            <?php echo htmlspecialchars($body); ?>
          </textarea></td>
        </tr>
        <tr><td class="label"><label for="submit">Send:</label></td><td id="submit"><button type="submit">Send message</button></td></tr>
      </table>
    </form>

    <?php
    }
    ?>

    Cancel and return to 
    <?php
    if (isset($_SESSION[first_name]))
    echo 
    "<a href=\"member.php\">your page</a>";
    else 
    echo 
    "<a href=\"index.php\">the home page</a>";
    ?>.
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles