Jump to content

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING


phpnewbieca

Recommended Posts

I am receiving the following error:
[b]Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/xgasq39z/public_html/guestbk_c.php on line 43[/b]

this is line 43 --> $fc = "\n".$Date."\n".$Name."\n".$Church."\n".$City."\n".$State."\n".$Comments."\n";

I am trying to write the data from a form to a text file.  

What am I doing wrong? The code is below:

[code}
<?php
error_reporting(E_ALL);
// Define variables  
$Date = date("M d, Y");
$file = "my_file.txt";
$Pastor ="[email protected]";
$Webmaster = "[email protected]";
$Alladdresses = "$Pastor, $Webmaster";
//Get Data From Form
$AddName = $_POST['Addname'];
$ViewGuestbook = $_POST['Viewguestbk'];
if(isset($_POST['Name'])) {
  $Name = $_POST['Name'];
}
else {
  echo " ERROR - You did not enter a Name\n";
}
$Church = $_POST['Church'];
$City = $_POST['City'];
$State = $_POST['State'];
if(isset($_POST['Comments'])) {
  $Comments = $_POST['Comments'];
}
else {
  echo " ERROR - You did not enter a Comment\n";
}
if(isset($_POST['PastorContact'])) {
  $PastorContact = $_POST['PastorContact'];
}
if(isset($_POST['PastorContact_2'])) {
  $PastorContact_2 = $_POST['PastorContact_2'];
}
// validation expected data exists
if(!isset($_POST['Name']) && !isset($_POST['Comments'])) {
  echo "Sorry, Name and Comments fields are required.";
  die;
}
       //Check which button was clicked 
       if ($AddName'] == "Add Name") {
      [b]  // Write Information to File 1[/b]
      $file_name = "$file";
      $fh = fopen($file_name, "a+");
43  $fc = "\n".$Date."\n".$Name."\n".$Church."\n".$City."\n".$State."\n".$Comments."\n";
      fwrite($fh,$fc);
      fclose($fh);
      echo "Form data successfully written to file 1";
  // Call Functions
  Guestbk_1();
  Guestbk_2();
  Guestbk_3();
  Guestbk_4();
  Guestbk_5();
}
else {
if ($ViewGuestbook == "View Guest Book") {
  // Call Functions
  Guestbk_4();
}
// FUNCTIONS
// Write Information to File 2
// function Guestbk_1() {
//  global  $Date, $file, $Pastor, $Webmaster, $Alladdresses, $Name, $Church, $City, $State, 
//  $Comments;
//  if(empty($Name) || empty($Comments)) {
//   echo "<h3>Sorry Name and Comments fields are required</h3>";
//  } 
//  else {
//   $fh = fopen($file,'a+');
//    if(!$fh) {
//     die("couldn't open file <i>$file</i>");
//    }
//    else {
//     $str = "\r\n";
//     $str.= "$Date\r\n"; 
//     $str.= "Guest: $Name\r\n";
//     $str.= "$Church\r\n";
//     $str.= "$City, $State\r\n";
//     $str.= "$Comments\r\n"; 
//     $str.= "\r\n"; 
//     fwrite($fh, $str);
//     echo "Form data successfully written to file 2";
//    }
//    fclose($fh);
//   } 
//  }
// FUNCTION
function Guestbk_2() {
  // Notify the Pastor of Entry
  global  $Date, $file, $Pastor, $Webmaster, $Alladdresses, $Name, $Church, $City, $State, $Comments, $PastorContact, $PastorContact_2;
  $fh = fopen($file,"r");
  if(!$fh) {
   die("couldn't open file <i>$file</i>");
  }
  else {
   $file = file_get_contents("$file");
  }
  fclose($fh);
  if(strstr($file,$Date)) { 
   $subject = "New Guestbook Entry";
   $email_message = "A new entry has been made to the GUESTBOOK.\n";
   if ($PastorContact == "Yes" && $PastorContact_2 != " "){
    $email_message.= "$Name would like you to contact them at $PastorContact_2\n";
   }
   else {
   echo "You did not enter a telephone number.\n";
   }
   // create email headers
   $headers = "From: ".$Webmaster."\r\n".
   "Reply-To: ".$Webmaster."\r\n".
   "X-Mailer: PHP/".phpversion();
   $formsent = mail($Webmaster, $subject, $email_message, $headers);
   if($formsent) {
    echo $formsent;
    echo " Thank you, for adding your information to our GUESTBOOK.\n";
   }
  } 
}
// FUNCTION
// Display Added Name to Browser
function Guestbk_3() {
  global  $Date, $file, $Pastor, $Webmaster, $Alladdresses, $Name, $Church, $City, $State, $Comments,  $PastorContact, $PastorContact_2;
  echo " <html>\n";
  echo " <head>\n";
  echo " <title> Added Name</title>\n";
  echo " </head>\n";
  echo " <BODY BGCOLOR='#000080' TEXT='white' link='yellow'>\n"; 
  echo " <table align='center' width='100%'>\n";
  echo " <tr>\n";
  echo " <td align='center'>\n";
  echo " <h1>Thank you for adding your name to our Guestbook</h1>\n";
  echo " <br />\n";
  echo " <font size='+2'> The information you added to our Guestbook is below.\n";
  echo " </font>\n";
  echo " </td>\n";
  echo " </tr>\n";
  echo " </table>\n";
  echo " <br /><br /><br />\n";
  echo " <table width='699' align='center' border='12'>\n";
  echo " <tr>\n";
  echo " <th align='right' valign='top' colspan='1' width='165'>\n";
  echo " Date:\n";
  echo " </th>\n";
  echo " <th align='left' valign='middle' colspan='1'>\n";
  echo " $Date\n";
  echo " </th>\n";
  echo " </tr>\n";
  echo " <th align='right' valign='top' colspan='1' width='165'>\n";
  echo " <b>Name: *</b> \n";
  echo " </th>\n";
  echo " <th align='left' valign='middle' colspan='1'>\n";
  echo " $Name\n";
  echo " </th>\n";
  echo " </tr>\n";
  echo " <tr>\n";
  echo " <th align='right' valign='top' colspan='1' width='165'>\n";
  echo " <b>Home Church: </b> \n";
  echo " </th>\n";
  echo " <th align='left' valign='middle' colspan='1'>\n";
  echo " $Church\n";
  echo " </th>\n";
  echo " </tr>\n";
  echo " <tr>\n";
  echo " <th align='right' valign='top' colspan='1' width='165'>\n";
  echo " City, State\n";
  echo " </th>\n";
  echo " <th align='left' valign='top' colspan='1' width='165'>\n";
  echo " <b>$City, $State: </b> \n";
  echo " </th>\n";
  echo " </tr>\n";
  echo " <tr>\n";
  echo " <th align='right' valign='middle' colspan='1' width='165'>\n";
  echo " <b>Comments: *</b> \n";
  echo " </th>\n";
  echo " <th align='left' valign='middle' colspan='1'>\n";
  echo " $Comments\n";
  echo " </th>\n";
  echo " </tr>\n";
  echo " </table>\n";
  if($PastorContact == "Yes") {
   echo " <table align='center'>\n";
   echo " <tr>\n";
   echo " <td align='center'>\n";
   echo " <font size='+2'> The information below <b><u>will not</b></u> be added to the guestbook </font>\n";
   echo " </td>\n";
   echo " </tr>\n";
   echo " <tr>\n";  
   echo " <td align='center'>\n";
   echo " <b>Would you like the pastor to contact you?</b> $PastorContact\n";
   echo " <br />\n";
   if ($PastorContact_2 == " ") {
    echo " ERROR - You did not enter a Contact Telephone Number.\n";
   }
   else {
   echo " <b>My telephone number is:</b> $PastorContact_2\n";
   }
   echo " </td>\n";
   echo " </tr>\n";
   echo " </table>\n";
  }
  echo " <BR /><BR />\n";
  echo " <table align='center'>\n";
  echo " <tr>\n";
  echo " <td>\n";
  echo " <font size='+2'>\n";
  echo " <a href=\"guestbkform_c.html\"><font size='+1' color='yellow'>Guestbook</font></a>\n";
  echo " </font>\n"; 
  echo " </td>\n";
  echo " </tr>\n";
  echo " </table>\n"; 
  echo " </body>\n";
  echo " </html>\n";
}
// FUNCTION
// Display Guestbook to Browser 
function Guestbk_4() {
  global $file;
  $filesize = "4096";
  $fh = fopen($file,'r'); 
  if(!$fh) {
   echo "Sorry there was an error please <a href=\"www.horace-franklin-jr.com/webmaster.html\">contact us now</a>";
   die("couldn't open file <i>$file</i>");
  }
  else {
   $con = fread($fh,$filesize($file));
   fclose ($fh);
   echo "<html>\n";
   echo "<head>\n";
   echo "<title> Guestbook Display</title>\n";
   echo "</head>\n";
   echo "<body bground='blue' text='white' link='yellow' vlink='red'>\n";
   echo "<table align='center'>\n";
   echo "<tr>\n";
   echo "<td align='center'>\n";
   echo "<font size='+2'> Lifeline Temple C.O.G.I.C. - Guestbook</font>\n";
   echo "</td>\n";
   echo "</tr>\n";
   echo "</table>\n";
   echo "<table>\n";
   echo "<tr>\n";
   echo "<td>\n";
   echo "$con\n";
   echo "<hr>\n";
   echo "</td>\n";
   echo "</tr>\n";
   echo "</table>\n";
   echo "<table>\n";
   echo "</body>\n";
   echo "</html>\n";
  }
}
function Guestbk_5() {
  // Email Webmaster
  global $Date; 
  $SendTo = "[email protected]";
  $From = "[email protected]";
  $Subject = "Lifeline Temple C.O.G.I.C - Guestbook";
  //supply the text and html versions of your email message 
  $text = "Review for errors or bad language.\n";
  $html = "Review for errors or bad language.\n";
  //provide path to the file to be attached 
  $file = '/home/xgasq39z/public_html/g_bk.txt';
  //create a boundary string. It must be unique 
  //so we use the MD5 algorithm to generate a random hash 
  $random_hash = md5(date('r',time())); 
  //define the headers we want passed. Note that they are separated with \r\n 
  $headers = "From: "."<"."$From".">"."\n";
  $headers.= "Reply-To: "."<"."$From".">"; 
  //add boundary string and mime type specification
  $headers.= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-{$random_hash}\""; 
  //read the atachment file contents into a string, 
  //encode it with MIME base64, 
  //and split it into smaller chunks 
  $attachment = chunk_split(base64_encode(file_get_contents($file))); 
  //define the body of the message. 
  $body = "--PHP-mixed-{$random_hash}\r\n".
  "Content-Type: multipart/alternative;
  boundary=\"PHP-alt-{$random_hash}\"\r\n".
  "--PHP-alt-{$random_hash}\r\n"."Content-Type: text/plain;
  charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n".
  "{$text}\r\n\r\n"."--PHP-alt-{$random_hash}\r\n\r\n".
  "Content-Type: text/html; charset=\"iso-8859-1\"\r\n".
  "Content-Transfer-Encoding: 7bit\r\n\r\n". "{$html}\r\n\r\n".
  "--PHP-alt-{$random_hash}--\r\n\r\n"."--PHP-mixed-{$random_hash}\r\n".
  "Content-Type: ".mime_content_type($file)."; name=\"".
  basename($file)."\"\r\n"."Content-Transfer-Encoding: base64\r\n".
  "Content-Disposition: attachment\r\n\r\n"."{$attachment}\r\n".
  "--PHP-mixed-{$random_hash}--\r\n\r\n"; 
  //send the email 
  $mail_sent = @mail($SendTo, $Subject, $body, $headers); 
  if($mail_sent){
   echo $mail_sent;
   echo "Thank you!\n";
  }
  else {
   echo "Email was not sent\n";
  }
}
?> 

 

What is this....

 

  // Write Information to File 1

 

doing in there?

I think he's trying to point out the line where the error message says the error is.

 

The actual problem is on the line before it:

 

if ($AddName'] == "Add Name") {

 

You have '] which shouldn't be there.

 

if ($AddName == "Add Name") {

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.