how do you fix Parse error: syntax error, unexpected $end in

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • togoode
    New Member
    • Nov 2011
    • 3

    how do you fix Parse error: syntax error, unexpected $end in

    Hello everyone, I'm new to php and to forums so please be gentle.

    I'm trying to create my first form and php script for a website that will allow the user to send their info to me in an email. Then the user will get a response that their info was recieved.

    I'm getting this error code:
    Parse error: syntax error, unexpected $end in /home/tgoode/prospectingtrea sures/contactus.php on line 77

    This is the php I have:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Underconstruction Page</title>
    </head>
    
    <body>
    <?php
    $to = $_REQUEST['sendto'];   // are these 1st 2 varaible correct?
    $from = $_REQUEST['email'];
    $name = $_REQUEST['name'];
    $address1 = $_REQUEST['address1'];
    $address2 = $_REQUEST['address2'];
    $city = $_REQUEST['city'];
    $county = $_REQUEST['county'];
    $state = $_REQUEST['state'];
    $zip = $_REQUEST['zip'];
    $phone = $_REQUEST['phone'];
    $fax = $_REQUEST['fax'];
    $webaddress = $_REQUEST['webaddress'];
    $email = $_REQUEST['email'];
    $messages = $_REQUEST['messages'];
    $headers = "From: $from";
    $subject = "Web Contact Data";
    
    $fields = array();
    	$fields{"name"} = "name";
    	$fields{"address1"} = "address1";
    	$fields{"address2"} = "address2"; // not required
    	$fields{"city"} = "city";
    	$fields{"county"} = "county";
    	$fields{"state"} = "state";
    	$fields{"zip"} = "zip";
    	$fields{"phone"} = "phone"; // not required
    	$fields{"fax"} = "fax"; // not required
    	$fields{"webaddress"} = "webaddress";
    	$fields{"email"} = "email";
    	$fields{"messages"} = "messages"; // not required
    	
    [B]//what does this line do?[/B]
    $body = "We have recieved the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: $s\n",$b,$_REQUEST[$a]);}
    
    $headers2 = "From: prospectingtreasures.com";
    $subject2 = "Thank you for contacting us";
    $autoreply = "Thank you for contacting us " . name . ". You should here from us usally within 48 hours. If you have more questions or requests, please email us at prospectingtreasures@gmail.com/";
    
    if($from =='') {print "You have not entered an email, please enter";}
    else {
    if($name == '') {print "You have not entered a name or company name, please go back and enter a name";}
    else {
    if($address1 == '') {print "You forgot to enter a street address, please go back and enter an address";}
    else {
    if($city == '') {print "You forgot to enter your city, please go back and enter your city";}
    else {
    if($county == '') {print "You forgot to enter your county, please go back and enter your county";}
    else {
    if($state == '') {print "You forgot to enter your state, please go back and enter your state";}
    else {
    if($zip == '') {print "you forgot to enter your zipcode, please go back and enter yor zipcode";}
    else {
    if($webaddress == '') {print " You forgot to give us your web address, please enter you web address";}
    else {
    if($email == '') {print "You have not entered an email address, please go back and enter your email address";}
    
    $send = mail($to, $subject, $body, $headers);    
    $send2 = mail($from, $subject2, $autoreply, $headers2);
    if($send)
    {header( " Location: http://www.prospectingtreasures.com/tgoode/thankyou.php" );}  [B]//what does this line do?[/B]
    else
    {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com";}
    [B]}//where is th open?
    }//where is th open?[/B]}
    
    //been lookin at this all day for missing brackets and comma and such, wondering if its something else?
    
    ?>
    </body>
    </html>
    thank you in advance for the help
    please help me get started in understanding
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    //been lookin at this all day for missing brackets and comma and such, wondering if its something else?
    I’m not sure how you counted the braces, I’ve found at least 6 missing closing ones.

    and line 27 - 39 are way off, too. you should read up on how to define an array sensibly.

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      hi togoode
      here is the fixed version , the constraints check if else where you are checking for empty email and from field, you were missing approx 9 closing braces :S , and you would have figured it out if you had right code indent , thats why it is important look at the code now.
      Code:
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Underconstruction Page</title>
          </head>
           
          <body>
          <?php
          $to = $_REQUEST['sendto'];   // are these 1st 2 varaible correct?
          $from = $_REQUEST['email'];
          $name = $_REQUEST['name'];
          $address1 = $_REQUEST['address1'];
          $address2 = $_REQUEST['address2'];
          $city = $_REQUEST['city'];
          $county = $_REQUEST['county'];
          $state = $_REQUEST['state'];
          $zip = $_REQUEST['zip'];
          $phone = $_REQUEST['phone'];
          $fax = $_REQUEST['fax'];
          $webaddress = $_REQUEST['webaddress'];
          $email = $_REQUEST['email'];
          $messages = $_REQUEST['messages'];
          $headers = "From: $from";
          $subject = "Web Contact Data";
           
          $fields = array();
      	$fields{"name"} = "name";
      	$fields{"address1"} = "address1";
      	$fields{"address2"} = "address2"; // not required
      	$fields{"city"} = "city";
      	$fields{"county"} = "county";
      	$fields{"state"} = "state";
      	$fields{"zip"} = "zip";
      	$fields{"phone"} = "phone"; // not required
      	$fields{"fax"} = "fax"; // not required
      	$fields{"webaddress"} = "webaddress";
      	$fields{"email"} = "email";
      	$fields{"messages"} = "messages"; // not required
           
          //what does this line do?
          $body = "We have recieved the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: $s\n",$b,$_REQUEST[$a]);}
           
          $headers2 = "From: prospectingtreasures.com";
          $subject2 = "Thank you for contacting us";
          $autoreply = "Thank you for contacting us " . $name . ". 
      	You should here from us usally within 48 hours. If you have more questions or requests, please email us at prospectingtreasures@gmail.com/";
           
          if($from =='') {
      		print "You have not entered an email, please enter";
      	}else {
      		if($name == '') {
      			print "You have not entered a name or company name, please go back and enter a name";
      		}else {
      			if($address1 == '') {print "You forgot to enter a street address, please go back and enter an address";
      			}else {
      				if($city == '') {print "You forgot to enter your city, please go back and enter your city";
      				}else {
      					if($county == '') {print "You forgot to enter your county, please go back and enter your county";
      					}else {
      						if($state == '') {print "You forgot to enter your state, please go back and enter your state";
      						}else {
      							if($zip == '') {print "you forgot to enter your zipcode, please go back and enter yor zipcode";
      							}else {
      								if($webaddress == '') {
      									print " You forgot to give us your web address, please enter you web address";
      								}else {
      									if($email == '') {
      										print "You have not entered an email address, please go back and enter your email address";
      									}
      								}
      							}
      						}
      					}
      				}
      			}
      		}
      	}
           
          $send = mail($to, $subject, $body, $headers);    
          $send2 = mail($from, $subject2, $autoreply, $headers2);
      	if($send){
      		header( " Location: http://www.prospectingtreasures.com/tgoode/thankyou.php" );
      	}else{
      		print "We encountered an error sending your mail, please notify webmaster@YourCompany.com";
      	}
      
          ?>
          </body>
          </html>

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        why using else { if () {} } when you can use elseif () {} ?

        how to define an array:
        Code:
        $fields = array(
            "name" => "name",
            "address" => "address",
            "zip" => "zip"
        );

        Comment

        • omerbutt
          Contributor
          • Nov 2006
          • 638

          #5
          yes ,
          i agree with dormilich in case of the ifelse as the current method is really old and confusing
          regards,
          Omer Aslam

          Comment

          • togoode
            New Member
            • Nov 2011
            • 3

            #6
            Thanks much omerbutt and Dormilich. I got it going but I need to touch it up a liitle. It gets real hard to see all them brackets. I only started PHP bout 3 weeks ago so I'm still trying to get the syntax. I will have to study more on the arrays Dormalich. Thanks again. Keep an eye out, I ask alot of questions. :)

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              the brackets are no problem if you indent them properly.

              Comment

              • togoode
                New Member
                • Nov 2011
                • 3

                #8
                I see that Dreamweaver's IDE will make the correct indentions if I were to let it. I had tabbed them all back so could see the code better. Guess I shouldn't do that. Thanks buddy.

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  there is certainly a setting that lets you control, how wide a tab is (e.g. 2, 4 or 8 spaces)

                  if you need that much nesting, there might also be something wrong with the programme logic.

                  Comment

                  • omerbutt
                    Contributor
                    • Nov 2006
                    • 638

                    #10
                    if you need that much nesting, there might also be something wrong with the programme logic.
                    :D...hahah .....somehow right,
                    Omer Aslam
                    Last edited by Dormilich; Nov 10 '11, 04:15 PM.

                    Comment

                    Working...