Jump to content


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


Parse Error:

Recommended Posts

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\Program Files\Apache Group\Apache2\htdocs\edit_policy_holder.php on line 62

This is the error msg I get when trying to create a web form that edits records in a database.

This is my code:

BODY {font-family:arial;}
.error {font-weight:bold; color:#FF0000;}
<h2>Edit Policy Holder Details:</h2>

// connect to the database
include 'includes/db_conn.txt';

// has form been submitted?
if ($_POST){
  foreach($_POST as $k => $v){
    $v = trim($v) ;
    $$k = $v;
  // build UPDATE query
  $update = "UPDATE policy_holder SET
    title='$t', first_name='$fn', surname='$sn', date_of_birth='$dob', uk_residency='$uk',
    marital_status='$ms', disability='$d', employment_status='$es', address_line_1='$ad1',
    area='$a', town='$tn', county='$c', post_code='$pc', telephone_work='$tw',
    telephone_home='$th', fax_number='$fax', email='$em'
    WHERE Id=$id";
  // execute query and check for success
  if (!mysqli_query($link, $update)){
    $msg = "Error updating data - " .mysqli_error($link);
  }else {
  $msg = "Record successfully updated:";

      // write table row confirming data
      $table_row = <<<EOR

// if not posted, check that an Id has been passed via the URL
  } else {
    if (!IsSet($_GET['id'])) {
      $msg = "No policy owner selected!";
    } else {
      $id = $_GET['id'];

      // build and execute the query
      $select = "SELECT title, first_name, surname, date_of_birth, uk_residency,
      marital_status, disability, employment_status, address_1_line, area, town, county,
      post_code, telephone_work, telephone_home, fax_number, email FROM policy_holder
      WHERE Id=$id";
      $result = mysqli_query($link, $select);
      // check that the record exists
      if (mysqli_num_rows($result)<1) {
        $msg = "No policy holder with that ID found!";
      } else {
      // set vars for form code
      $form_start = "<FORM METHOD=\"post\"ACTION= \"" . $_SERVER['PHP_SELF']. "\">";
      $form_end = <<<EOF
          <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Submit changes" /></TD>
          <TD COLSPAN="2"><INPUT TYPE="reset" VALUE="Cancel" /></TD>
// assign the results to an array
while ($row = mysqli_fetch_array($result)) {
  $t = $row['title'];
  $fn = $row['first_name'];
  $sn = $row['surname'];
  $dob = $row['date_of_birth'];
  $uk = $row['uk_residency'];
  $ms = $row['marital_status'];
  $d = $row['disability'];
  $es = $row['employment_status'];
  $ad1 = $row['address_1_line'];
  $a = $row['area'];
  $tn = $row['town'];
  $c = $row['county'];
  $pc = $row['post_code'];
  $tw = $row['telephone_work'];
  $th = $row['telephone_home'];
  $fax = $row['fax_number'];
  $em = $row['email'];
  // write table row with form fields
  $table_row = <<<EOR
    <TD><INPUT TYPE="text" NAME="title" VALUE="$t" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="first_name" VALUE="$fn" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="suranme" VALUE="$sn" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="date_of_birth" VALUE="$dob" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="uk_residency" VALUE="$uk" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="marital_status" VALUE="$ms" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="disability" VALUE="$d" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="employment_status" VALUE="$es" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="address_1_line" VALUE="$ad1" SIZE="25"/></TD>
    <TD><INPUT TYPE="text" NAME="area" VALUE="$a" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="town" VALUE="$tn" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="county" VALUE="$c" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="post_code" VALUE="$pc" SIZE="10"/></TD>
    <TD><INPUT TYPE="text" NAME="telephone_work" VALUE="$tw" SIZE="11"/></TD>
    <TD><INPUT TYPE="text" NAME="telephone_home" VALUE="$th" SIZE="11"/></TD>
    <TD><INPUT TYPE="text" NAME="fax_number" VALUE="$fax" SIZE="11"/></TD>
    <TD><INPUT TYPE="text" NAME="email" VALUE="$em" SIZE="20"/></TD>
// end 'if record exists' if
      // end 'if ID given in URL' if
      // end 'if form posted' if
    // close connection
    // print error/success message
    echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" :"";

    <!-- Show start-of-form code if form needed -->
    <? echo (IsSet($form_start)) ? $form_start :""; ?>
    INPUT TYPE="HIDDEN" NAME="id" VALUE="<? echo $id ?>" />
      <TH>First name</TH>
      <TH>Last name</TH>
      <TH>Date of birth</TH>
      <TH>UK Residency</TH>
      <TH>Marital Status</TH>
      <TH>Employment Status</TH>
      <TH>Address line 1</TH>
      <TH>Post Code</TH>
      <TH>Telephone work</TH>
      <TH>Telephone home</TH>
      <TH>Fax number</TH>
    <!-- Show appropriate table row code (none set if there were errors) -->
    <? echo (IsSet($table_row)) ? $table_row :""; ?>
    <!-- Show end-of-form code if we are displaying the form -->
    <? echo (IsSet($form_end)) ? $form_end :""; ?>
    <br/><a href="policylist.php">Back to policy holder list</a>

Can anybody spot where I am going wrong?

Share this post

Link to post
Share on other sites
I see you are using HEREDOC syntax on large text strings. This is fine however, You cannot indent or put anythink before or after the closing HEREDOC tag. Eg you cannot do this:
[code]$str = <<<EOF
large text string
You see EOF; that has be in the first column of the line its on, it cannot be indented or having before or after it it has to be on a new line on its own.
[code]$str = <<<EOF
large text string

This is whats causing this error. The lines your want to change are line 57, 86, and 129

Share this post

Link to post
Share on other sites
I am not sure what you mean. Do you get any errors? If you dont then it may be a bug in your code.

Also I see you have all your database credentials in a text file (includes/db_conn.txt) I strongly suggest you use php file extension rather than txt, otherwise anyone will be able to know your database login details by going to that file. Chnage it to .php and they wont be able to see it, it'll just be a blank screen.

Share this post

Link to post
Share on other sites


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.