Jump to content

Parse Error:


benjamin_boothe

Recommended Posts

[quote]
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
[/quote]

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

This is my code:

[code]
<HTML>
<HEAD>
<STYLE>
BODY {font-family:arial;}
.error {font-weight:bold; color:#FF0000;}
</STYLE>
</HEAD>
<BODY>
<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
      <TR>
          <TD>$t</TD>
          <TD>$fn</TD>
          <TD>$sn</TD>
          <TD>$dob</TD>
          <TD>$uk</TD>
          <TD>$ms</TD>
          <TD>$d</TD>
          <TD>$es</TD
          <TD>$ad1</TD>
          <TD>$a</TD>
          <TD>$tn</TD>
          <TD>$c</TD>
          <TD>$pc</TD>
          <TD>$tw</TD>
          <TD>$th</TD>
          <TD>$fax</TD>
          <TD>$em</TD>
      </TR>
      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
      <TR>
          <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Submit changes" /></TD>
          <TD COLSPAN="2"><INPUT TYPE="reset" VALUE="Cancel" /></TD>
      </TR>
      </FORM>
      EOF;
     
// 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
<TR>
    <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>
</TR>
  EOR;
}
// end 'if record exists' if
      }
      // end 'if ID given in URL' if
      }
      // end 'if form posted' if
    }
   
    // close connection
    mysqli_close($link);
   
    // print error/success message
    echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" :"";
    ?>

    <TABLE BORDER="1" CELLPADDING="5">
    <!-- Show start-of-form code if form needed -->
    <? echo (IsSet($form_start)) ? $form_start :""; ?>
   
    INPUT TYPE="HIDDEN" NAME="id" VALUE="<? echo $id ?>" />
    <TR>
      <TH>Title</TH>
      <TH>First name</TH>
      <TH>Last name</TH>
      <TH>Date of birth</TH>
      <TH>UK Residency</TH>
      <TH>Marital Status</TH>
      <TH>Disability</TH>
      <TH>Employment Status</TH>
      <TH>Address line 1</TH>
      <TH>Area</TH>
      <TH>Town</TH>
      <TH>County</TH>
      <TH>Post Code</TH>
      <TH>Telephone work</TH>
      <TH>Telephone home</TH>
      <TH>Fax number</TH>
      <TH>Email</TH>
    </TR>
    <!-- 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 :""; ?>
    </TABLE>
   
    <br/><a href="policylist.php">Back to policy holder list</a>
    </BODY>
    </HTML>
[/code]

Can anybody spot where I am going wrong?
Link to comment
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
  EOF;[/code]
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
EOF;[/code]

This is whats causing this error. The lines your want to change are line 57, 86, and 129
Link to comment
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.
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.