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
https://forums.phpfreaks.com/topic/122886-parse-error/
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 = "[email protected]"; 
$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 

[email protected]"; } 
?> 

 

What did I do wrong?

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

Link to comment
https://forums.phpfreaks.com/topic/122886-parse-error/#findComment-634670
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

 

[email protected]"; }

 

And you use { } incorrectly throughout all your code.

Link to comment
https://forums.phpfreaks.com/topic/122886-parse-error/#findComment-634724
Share on other sites

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

 

<?php 
$to = "[email protected]"; 
$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 [email protected]";
}

}
?> 

 

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

Link to comment
https://forums.phpfreaks.com/topic/122886-parse-error/#findComment-636464
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
https://forums.phpfreaks.com/topic/122886-parse-error/#findComment-636465
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.