How to fix parse error: syntax error, unexpected $end in

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vultren

    How to fix parse error: syntax error, unexpected $end in

    Parse error: syntax error, unexpected $end in

    I keep getting that, I have no clue where to fix it. Any help would be VERY APPRECIATED!

    Code:
    <?php
    if(isset($_POST['email'])) {
    	
    	// EDIT THE 2 LINES BELOW AS REQUIRED
    	$email_to = "tony@example.com";
    	$email_subject = "New Email from CASE EVALUATION form in email";
    	
    	
    	function died($error) {
    		// your error code can go here
    		echo "We are very sorry, but there were error(s) found with the form your submitted. ";
    		echo "These errors appear below.<br /><br />";
    		echo $error."<br /><br />";
    		echo "Please go back and fix these errors.<br /><br />";
    		die();
    	}
    	
    	// validation expected data exists
    	if(!isset($_POST['full_name']) ||
    		!isset($_POST['address']) ||
    		!isset($_POST['phone']) ||
    		!isset($_POST['email']) ||
    		!isset($_POST['best']) ||
    		!isset($_POST['role_in_matter']) ||
    		!isset($_POST['where']) ||
    		!isset($_POST['when']) ||
    		!isset($_POST['what']) ||
    		!isset($_POST['what_two']) ||
    		!isset($_POST['what_three']) ||
    		!isset($_POST['comments'])) {
    		died('We are sorry, but there appears to be a problem with the form your submitted.');		
    	}
    	
    	$full_name = $_POST['full_name']; // required
    	$address = $_POST['address']; // required
    	$phone = $_POST['phone']; // required
    	$email = $_POST['email']; // required
    	$best = $_POST['best']; // required
    	$role_in_matter = $_POST['role_in_matter']; // required
    	$where = $_POST['where']; // required
    	$when = $_POST['when']; // required
    	$what = $_POST['what']; // required
    	$what_two = $_POST['what_two']; // not required
    	$what_three = $_POST['what_three']; // not required
    	$comments = $_POST['comments']; // required
    	
    	$error_message = "";
    	$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!eregi($email_exp,$full_name)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }
    	$string_exp = "^[a-z0-9 .'-]+$";
      if(!eregi($string_exp,$address)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }
      $string_exp = "^[a-z0-9 .'-]+$";
      if(!eregi($string_exp,$phone)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }  
      $string_exp = "[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
      if(!eregi($string_exp,$email)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }  
      $string_exp = "^[a-z0-9 .'-]+$";
      if(!eregi($string_exp,$best)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }  
      $string_exp = "^[a-z0-9]+$";
      if(!eregi($string_exp,$role_in_matter)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }  
      $string_exp = "^[a-z0-9 .'-]+$";
      if(!eregi($string_exp,$where)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }  
      $string_exp = "^[a-z0-9 .'-]+$";
      if(!eregi($string_exp,$when)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }  
      if(!eregi($string_exp,$what)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }
      $string_exp = "^[a-z0-9 .'-]+$";
      if(!eregi($string_exp,$what_two)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
    	
      $string_exp = "^[a-z0-9 .'-]+$";
      if(!eregi($string_exp,$what_three)) {
      	$error_message .= 'The text you entered does not appear to be valid.<br />';
      }
      if(strlen($comments) < 2) {
      	$error_message .= 'The pertinent information you entered do not appear to be valid.<br />';
      }
      
      if(strlen($error_message) > 0) {
      	died($error_message);
      }
    	$email_message = "Form details below.\n\n";
    	
    	function clean_string($string) {
    	  $bad = array("content-type","bcc:","to:","cc:","href");
    	  return str_replace($bad,"",$string);
    	}
    	
    	$email_message .= "Full Legal Name: ".clean_string($full_name)."\n";
    	$email_message .= "Your address: ".clean_string($address)."\n";
    	$email_message .= "Your phone number: ".clean_string($phone)."\n";
    	$email_message .= "Your email address: ".clean_string($email)."\n";
    	$email_message .= "Best time and way to contact you: ".clean_string($best)."\n";
    	$email_message .= "Your role in this matter: ".clean_string($role_in_matter)."\n";
    	$email_message .= "Where was the ticket received?: ".clean_string($where)."\n";
    	$email_message .= "When did you receive it? There are strict deadlines, so this is very important.: ".clean_string($when)."\n";
    	$email_message .= "What type of law enforcement officer stopped you?: ".clean_string($what)."\n";
    	$email_message .= "What is the allegation? : ".clean_string($what_two)."\n";
    	$email_message .= "What court your case is in: ".clean_string($what_three)."\n";
    	$email_message .= "Other Pertinent Information: ".clean_string($comments)."\n";
    	
    	
    // create email headers
    $headers = 'From: '.$full_name."\r\n".
    'Reply-To: '.$full_name."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);  
    ?>
    Last edited by Atli; Nov 2 '10, 08:10 AM. Reason: fixed [CODE] [/CODE] tags, replaced the real email address with an example value.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    The rest of the error, the part you didn't post, is the part that tells you where the error occurs. If you want us to be able to help locate it, we need to see that as well.

    This error, however, usually indicates that your brackets are out of order. Make sure you close all conditional blocks and functions properly.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Looks like you haven't closed that main if(). This is why programmers love consistent formatting.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        it looks like there should be a } on line #87.

        Comment

        • Vultren

          #5
          How to fix parse error: syntax error, unexpected $end in PART 2!

          Thank you for the responses guys. Here is my PHP for the site. There is something wrong, can anyone identity it? I would really appreciate it.

          Code:
          <?php
          if(isset($_POST['email'])) {
          	
          	// EDIT THE 2 LINES BELOW AS REQUIRED
          	$email_to = "renewalhomerestoration@gmail.com";
          	$email_subject = "New Email from contact form in email";
          	
          	
          	function died($error) {
          		// your error code can go here
          		echo "We are very sorry, but there were error(s) found with the form your submitted. ";
          		echo "These errors appear below.<br /><br />";
          		echo $error."<br /><br />";
          		echo "Please go back and fix these errors.<br /><br />";
          		die();
          	}
          	
          	// validation expected data exists
          	if(!isset($_POST['first_name']) ||
          		!isset($_POST['last_name']) ||
          		!isset($_POST['email']) ||
          		!isset($_POST['telephone']) ||
          		!isset($_POST['comments'])) {
          		died('We are sorry, but there appears to be a problem with the form your submitted.');		
          	}
          	
          	$first_name = $_POST['first_name']; // required
          	$last_name = $_POST['last_name']; // required
          	$email_from = $_POST['email']; // required
          	$telephone = $_POST['telephone']; // not required
          	$comments = $_POST['comments']; // required
          	
          	$error_message = "";
          	$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
            if(!eregi($email_exp,$email_from)) {
            	$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
            }
          	$string_exp = "^[a-z .'-]+$";
            if(!eregi($string_exp,$first_name)) {
            	$error_message .= 'The First Name you entered does not appear to be valid.<br />';
            }
             
            if(!eregi($string_exp,$last_name)) {
            	$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
            }
            if(strlen($comments) < 2) {
            	$error_message .= 'The Comments you entered do not appear to be valid.<br />';
            }
            $string_exp = "^[0-9 .-]+$";
            if(!eregi($string_exp,$telephone)) {
            	$error_message .= 'The Telphone Number you entered does not appear to be valid.<br />';
            }
            if(strlen($error_message) > 0) {
            	died($error_message);
            }
          	$email_message = "Form details below.\n\n";
          	
          	function clean_string($string) {
          	  $bad = array("content-type","bcc:","to:","cc:","href");
          	  return str_replace($bad,"",$string);
          	}
          	
          	$email_message .= "First Name: ".clean_string($first_name)."\n";
          	$email_message .= "Last Name: ".clean_string($last_name)."\n";
          	$email_message .= "Email: ".clean_string($email_from)."\n";
          	$email_message .= "Telephone: ".clean_string($telephone)."\n";
          	$email_message .= "Comments: ".clean_string($comments)."\n";
          	
          	
          // create email headers
          $headers = 'From: '.$email_from."\r\n".
          'Reply-To: '.$email_from."\r\n" .
          'X-Mailer: PHP/' . phpversion();
          @mail($email_to, $email_subject, $email_message, $headers);  
          ?>

          Here is the HTML for the form if this helps.

          Code:
          <form name="contact" method="post" action="contactform.php">
          <table width="550px">
          </tr>
          <tr>
           <td valign="top">
            <label for="first_name">First Name</label>
           </td>
           <td valign="top">
            <input  type="text" name="first_name" maxlength="50" size="30">
           </td>
          </tr>
          
           <td valign="top">
            <label for="last_name">Last Name</label>
           </td>
           <td valign="top">
            <input  type="text" name="last_name" maxlength="50" size="30">
           </td>
          </tr>
          <tr>
           <td valign="top">
            <label for="email">Return Email</label>
           </td>
           <td valign="top">
            <input  type="text" name="email" maxlength="80" size="30">
           </td>
          
          </tr>
          <tr>
           <td valign="top">
            <label for="telephone">Phone Number</label>
           </td>
           <td valign="top">
            <input  type="text" name="telephone" maxlength="30" size="30">
           </td>
          </tr>
          <tr>
           <td valign="top">
            <label for="comments">Comments</label>
           </td>
           <td valign="top">
            <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
           </td>
          
          </tr>
          <tr>
           <td colspan="2" style="text-align:center">
            <input type="submit" value="Submit">
           </td>
          </tr>
          </table>
          </form>
          And finally, here is the error when you use the contact form:

          Parse error: syntax error, unexpected $end in D:\Hosting\5235 613\html\newsit e\contactform.p hp on line 112

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Please do not repost the same question.

            You have been given an answer 3 times.

            Comment

            Working...