Jump to content

Recommended Posts

This code produces an "unexpected T_VARIABLE" error at line 98.  I have annotated line 98 in the code.  What does that mean and how do I fix it?

 

<?php
              include 'library/dbconfig.php';
              include 'library/opendb.php';
              
              if(isset($_POST['fullname'])) {
                  $query="SELECT client_id, first_name, last_name, company_name
                          FROM $dbname.clients";
                  $result=mysql_query($query) or die($query . '<br >'.mysql_error());
                  while($row=mysql_fetch_array($result)) {
                      if(!isset($row['company_name'])) {
                          //echo "$row[last_name], $row[first_name] ($row[client_id])<br>";
line 98->                UPDATE $dbname.clients SET full_name="$row[last_name], $row[first_name] ($row[client_id])";
                      } elseif(isset($row['company_name']) && ($row['last_name']!="")) {
                          //echo "$row[company_name]: $row[last_name], $row[first_name] ($row[client_id])<br>";
                          UPDATE $dbname.clients SET full_name="$row[company_name]: $row[last_name], $row[first_name] ($row[client_id])";
                      } else {
                          //echo "$row[company_name] ($row[client_id])<br>";
                          UPDATE $dbname.clients SET full_name="$row[company_name] ($row[client_id])";
                      }
                  }
                  echo "Function successfully run, constructed full_name field in the clients table.";
              }
              
              include 'library/closedb.php';
          ?>

 

Notice There are commented out echos. If I uncomment those echos and comment out the update code, the output is exactly what I need, so why do the update lines not work?

Link to comment
https://forums.phpfreaks.com/topic/129476-what-is-unexpected-t_variable/
Share on other sites

Here's an example of how to fix it (for the first error only):

 

              if(isset($_POST['fullname'])) {
                  $query="SELECT client_id, first_name, last_name, company_name
                          FROM $dbname.clients";
                  $result=mysql_query($query) or die($query . '<br >'.mysql_error());
                  while($row=mysql_fetch_array($result)) {
                      if(!isset($row['company_name'])) {
                          //echo "$row[last_name], $row[first_name] ($row[client_id])<br>";
line 98->                $query="UPDATE $dbname.clients SET full_name='{$row['last_name']}, {$row['first_name']} ({$row['client_id']})'";
                            $update_result = mysql_query($query) or die($query . '<br >'.mysql_error());

 

It's important that you use a different result variable inside the loop, otherwise you will overwrite the $result being used in the while().

 

The query also may not be correct yet, all I've fixed is the PHP syntax.

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.