Jump to content

parse error


mj1224

Recommended Posts

I am not a php person, and I get a pase error  :

Parse error: parse error in www.mywebsite/contact.php on line 35

 

Line 35 is the last line of that file.

 

I copied script from a code helper and loaded it but get that error when I fill in my form to submit it by email.

 

What did I do wrong?

 

Link to comment
Share on other sites

Here is the html  for my form:

 

<form name="gsginfo" method="post" action="contact.php">
   <h3>Would you like more information?</h3>
   <p> Name:  
     <input name="name" type="text" id="name" size="40" maxlength="40">
     <span class="style3">*</span></p>
   <p>Address:  
     <input name="address" type="text" id="address" size="60" maxlength="60">
   </p>
   <p>City:
     <input name="city" type="text" id="city" size="25" maxlength="25">
   </p>
   <p>State:
     <input name="state" type="text" id="state" size="2" maxlength="2">
   </p>
   <p>Zip:
     <input name="zip" type="text" id="zip" size="10" maxlength="10">
   </p>
   <p>Phone:
     <input name="phone" type="text" id="phone" size="15" maxlength="15">
     <span class="style3">*<span class="style2">In case we have problems with your email.</span></span></p>
   <p>Email:
     <input name="email" type="text" id="email" size="30" maxlength="30">
     <span class="style3">*</span></p>
   <p>Questions/Comments:
     <textarea name="comments" id="comments" cols="45" rows="5"></textarea>
   </p>
   <p> </p>
   <p>
     <input name="submit" type="submit" id="submit">
   </p>
</form>

and here is my php:

 

<?php 
$to = "tadams@forestry.state.sc.us"; 
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ; 
$header = "From: $from";
$subject = "Grow Some Green" ; 

$fields = array(); 
$fields{"name"} = "Name"; 
$fields{"address"} = "Address";
$fields{"city"} = "City";
$fields{"state"} = "State";
$fields{"zip"} = "Zip";
$fields{"phone"} = "Phone";
$fields{"email"} = "Email";
$fields{"comments"} = "Comments-Questions"; 

$body = "We have received the following information:"; foreach($fields as $a => $b){ 

$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 


$autoreply = "Thank you for your interest in Grow Some Green.  Someone will contact you 

shortly.  If you have any more questions, please consult our website at 

www.growsomegreen.com";


if($email == '') {print "You have not entered an email, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
if($phone == '') {print "You have not entered a phone number to get in touch with you in 

case we have problems replying to your email, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $header); 
if($send) 
{header( "Location: http://www.state.sc.us/forest/thankyou.htm" );} 
else 
{print "We encountered an error sending your mail, please notify 

webmaster@YourCompany.com"; } 
?> 

 

What did I do wrong?

Any help or suggestions wold be welcomed. I don't know php.

Link to comment
Share on other sites

You need to learn to indent

 

Where is the closing bracket for this else?

 

else {

$send = mail($to, $subject, $body, $header);

if($send)

{header( "Location: http://www.state.sc.us/forest/thankyou.htm" );}

else

{print "We encountered an error sending your mail, please notify

 

webmaster@YourCompany.com"; }

 

And you use { } incorrectly throughout all your code.

Link to comment
Share on other sites

I copied the code from another php helper website and just pasted it in.

I added a closing bracket qand it still doesn't work.

 

What difference does indenting make?

 

i don't know php, I'm sorry. just trying to make a simple form be emailed from our website.

Link to comment
Share on other sites

Here I fixed up your code, making it neater. Should work now:

 

<?php 
$to = "tadams@forestry.state.sc.us"; 
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ; 
$header = "From: $from";
$subject = "Grow Some Green" ; 

$fields = array(); 
$fields["name"] = "Name"; 
$fields["address"] = "Address";
$fields["city"] = "City";
$fields["state"] = "State";
$fields["zip"] = "Zip";
$fields["phone"] = "Phone";
$fields["email"] = "Email";
$fields["comments"] = "Comments-Questions"; 

$body = "We have received the following information:"; foreach($fields as $a => $b){ 
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

$autoreply = <<<html
Thank you for your interest in Grow Some Green.  Someone will contact you 
shortly.  If you have any more questions, please consult our website at 
www.growsomegreen.com
html;

if($email == ''){
print "You have not entered an email, please go back and try again";
}elseif($name == ''){
print "You have not entered a name, please go back and try again";
}elseif($phone == ''){
print "You have not entered a phone number to get in touch with you in case we have problems replying to your email, please go back and try again";
}else{

$send = mail($to, $subject, $body, $header);

if($send){
	header( "Location: http://www.state.sc.us/forest/thankyou.htm" );
}else{
	print "We encountered an error sending your mail, please notify webmaster@YourCompany.com";
}

}
?> 

 

The only difference indenting will make is the readability of your code. Good indentation is critical for good code, IMO.

Link to comment
Share on other sites

If you copied this code from another PHP helper site, why don't you ask the question there? This code has problems as written.

 

Also, using a piece of code with out knowing the language it's written in can be quite dangerous (IMHO).

 

Indenting doesn't make a difference when the code runs, it makes a difference when humans try to read it.

 

This code was written using some very old methods. It assumes that register_globals is enabled, which hasn't been the case in many years. It uses the archaic method of using "{ }" for indexing. And uses the $_REQUEST array instead of the $_POST array.

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.