Jump to content

what is unexpected T_VARIABLE?


Darkmatter5

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.

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.