Jump to content

[SOLVED] Parse Error Unexpected '}' expecting ')'


phpnewbieca

Recommended Posts

I am a newbie and I do not understand why I keep receiving this error:

Parse error: syntax error, unexpected '{', expecting '(' in contact_3.php on line 96 :o

 

I have checked all the { and ) to see if i opened a { or ( without closing it to no avail.

 

Please tell me what I am doing wrong.  The line the error is referring to is in the function Order(), see *** below.

 

<?php

// contact_3.php - processes contactform.html

$Date = date("D  d M Y - H:i:s ");

if(isset($_POST['email'])) {

  // Create Random Number

  srand ((double) microtime( )*1000000);

  $random_number = rand( );

  $random_number = "confirmation_number"; 

  $send_to = $_POST['send_to'];

  $first_name = $_POST['first_name'];

  $last_name = $_POST['last_name'];

  $suffix = $_POST['suffix'];

  $email = $_POST['email'];

  $telephone = $_POST['telephone'];

  $comments = $_POST['comments'];

// Call Functions

Order();

Contact();

Verify_email_address();

//FUNCTIONS

function Contact(){

  // Print to Browser

  global  $Date, $confirmation_number, $send_to, $first_name, $last_name, $suffix, $email, $telephone, $comments;   

  echo " <html>\n";

  echo " <head>\n";

  echo " <title>Contact Us</title>\n";

  echo " </head>\n";

  echo " <body bgcolor=\"black\" TEXT=\"silver\">\n";

  echo " <table width=\"600\" Align=\"center\">\n";

  echo " <tr>\n";

  echo " <td width=\"600\" Align=\"center\">\n";

  echo " <font size=\"+2\">~ ~ ~ CONTACT US ~ ~ ~</font>\n";

  echo " </td>\n";

  echo " </tr>\n";

  echo " </table>\n";

  echo " <table width=\"600\" Align=\"center\">\n";

  echo " <tr>\n";

  echo " <td width=\"600\" Align=\"left\">\n";

  echo " Date: $Date\n";

  echo " <br />\n";

  echo " Hello $first_name $last_name $suffix,\n";

  echo " <br />\n";

  echo " Thank you for contacting us. Someone will contact you, usually, within 24 hours.\n";

  echo " <br /><br />\n";

  echo " What you submitted is below:\n";

  echo " <br />\n";

  echo " <font size=\"+2\"> To: $send_to\n";

  echo " <br />\n";

  echo " First Name: $first_name\n";

  echo " <br />\n";

  echo " Last Name: $last_name\n";

  echo " <br />\n";

  echo " Suffix: $suffix\n";

  echo " <br />\n";

  echo " Email: $email\n";

  echo " <br />\n";

  echo " Telephone: $telephone\n";

  echo " <br />\n"; 

  echo " Comments: $comments <br />\n";

  echo " <br />\n";

  echo " Your CONFIRMATION NUMBER: $confirmation_number\n";

  echo " <br /><br />\n";

  echo " You will receive an email to VALIDATE your email address.\n";

  echo " <br /><br />\n";

  echo " Please visit us again <a href=\"http://www.horace-franklin-jr.com\">www.horace-franklin-jr.com</a>\n";

  echo " </td>\n";

  echo " </tr>\n";

  echo " </table>\n";

  echo " </body>\n";

  echo " </html>";

}

function Order(){

  global  $Date, $confirmation_number, $send_to, $first_name, $last_name, $suffix, $email, $telephone, $comments;   

  $myFile = "contact_us.txt";

  $fh = fopen($myFile,'a+') or die("can't open <i>$myFile</i>");

  if(!$fh) {

  die("couldn't open file <i>$myFile</i>");

  }

  else {

  rewind($fh);

  $str.= " Date: $Date\r\n"; 

  $str.= " Confirmation Number: $confirmation_number\r\n"; 

  $str.= " To: $send_to\r\n";

  $str.= " First Name: $first_name\r\n";

  $str.= " Last Name: $last_name\r\n";

  $str.= " Suffix: $suffix\r\n";

  $str.= " Email Address: $email\r\n";

  $str.= " Telephone: $telephone\r\n";

  $str.= " Comments: $comments\r\n"; 

  fwrite($fh, $str);

  echo "success writing to file";

***  }

  fclose($fh);

}

function Verify_email_address {

  global  $Date, confirmation_number, $send_to, $first_name, $last_name, $suffix, $email, $telephone, $comments;   

  // EDIT THE 2 LINES BELOW AS REQUIRED

  $send_to = "$send_to";

  $email_subject = "Re: Contact Us";

  // FUNCTION

function died() {

  // your error code can go here

  echo "These errors appear below.\n";

  echo "<br /><br />\n";

  echo "$error.\n";

  echo "<br /><br />\n";

  echo "Please go back and fix these errors.\n";

  echo "<br /><br />\n";

  die();

}

  // validation expected data exists

  if(!isset($_POST['send_to']) ||

  !isset($_POST['first_name']) ||

  !isset($_POST['last_name']) ||

  !isset($_POST['suffix']) ||

  !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.');

  }

  $send_to = $_POST['send_to'];

  $first_name = $_POST['first_name'];

  $last_name = $_POST['last_name'];

  $suffix = $_POST['suffix']; 

  $email = $_POST['email'];

  $telephone = $_POST['telephone'];

  $comments = $_POST['comments'];

 

  $error_message = "";

  $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";

  if(!eregi($email_exp,$send_to)) {

  $error_message .= 'The Email Address you entered does not appear to be valid.<br />';

  }

  if(!eregi($email_exp,$email)) {

  $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

function clean_string($string) {

  global  $Date, confirmation_number, $send_to, $first_name, $last_name, $suffix, $email, $telephone, $comments;   

  $bad = array("content-type","bcc:","to:","cc:","href");

  return str_replace($bad,"",$string);

}

   

  $subject ="Thank You";

  $email_message = "Hello, $first_name $last_name $suffix\n";

  $email_message .= "Thank you for contacting us. We will respond soon, usually within 48 hours.\n";

  $email_message .= "This is what you submitted:\n";

  $email_message .= "First Name: ".clean_string($first_name)."\n";

  $email_message .= "Last Name: ".clean_string($last_name)."\n";

  $email_message .= "Suffix: $suffix\n";

  $email_message .= "Email: ".clean_string($email)."\n";

  $email_message .= "Telephone: ".clean_string($telephone)."\n";

  $email_message .= "Comments: ".clean_string($comments)."\n";

  $email_message .= "Please validate your order by clicking Validate Order.\n";

  $email_message .= "You will need your Confirmation Number $confirmation_number and Email Address to validate your order.\n";

  $email_message .= "<a href=\"www.horace.franklin.jr.com/validated_orderform.php\"> Validate Order\n";

  // create email headers

  $headers = 'From: '.$send_to."\r\n".

  'Reply-To: '.$send_to."\r\n" .

  'X-Mailer: PHP/' . phpversion();

  $formsent = mail($email, $subject, $email_message, $headers);

  if ($formsent) {

  echo $formsent;

  } 

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/178689-solved-parse-error-unexpected-expecting/
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.