By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,064 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,064 IT Pros & Developers. It's quick & easy.

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

P: 2
I need some help with an error I'm getting using php 5.2.5 running on linux.

I receive an error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/inventoryControl/supplier.php on line 26 (line number changed to match code tags)

The code is as follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. // get a supplier using the supplier id
  3. function getSupplier($supplierID = NULL) {
  4.  
  5.     // initialize the supplier to the null
  6.     $supplier = NULL;
  7.  
  8.     // check for NULL arguments
  9.     if (!is_null($supplierID)) {
  10.  
  11.         // get the connection to the database
  12.         $con = db_connect();
  13.  
  14.         // sql select statement 
  15.         $sql = "SELECT * FROM suppliers WHERE supplier_id = '" . $supplierID . "'";
  16.  
  17.         // execute the query
  18.         $result = mysql_query($sql, $con);
  19.  
  20.         if ($record = mysql_fetch_assoc($result)) {
  21.  
  22.             // create empty supplier object
  23.             $supplier = new Supplier;
  24.  
  25.             // set attributes
  26.             $supplier->setSupplierID($supplierID);
  27.             $supplier->setFirstName($record['first_name']);
  28.             $supplier->setLastName($record['last_name']);
  29.             $supplier->setOrganization($record['organization']);
  30.             $supplier->setPhone($record['phone']);
  31.             $supplier->setFax($record['fax']);
  32.             $supplier->setMobile($record['mobile']);
  33.             $supplier->setEmail($record['email']);
  34.             $supplier->setAddress1($record['address1']);
  35.             $supplier->setAddress2($record['address2']);
  36.             $supplier->setCity($record['city']);
  37.             $supplier->setState($record['state']);
  38.             $supplier->setCountry($record['country']);
  39.             $supplier->setPostcode($record['postcode']);
  40.         } // if
  41.  
  42.         // close the database connection
  43.         db_close($con);
  44.     } // if
  45.  
  46.     // return found ? populated supplier : NULL
  47.     return $supplier;
  48. } // getSupplier()
The bit that's dying is any/all of the $supplier->setBlah($record['...']);

Strangely, I have code that is exactly the same in multiple software systems, including this one that are basically identical without the problem. Example of code without parse error:

Expand|Select|Wrap|Line Numbers
  1.  
  2. // get an instance of a Customer using the customerID
  3. function getCustomer($customerID = NULL) {
  4.  
  5.      // return value
  6.     $customer = NULL;
  7.  
  8.      // check for null arguments
  9.     if (!is_null($customerID)) {
  10.  
  11.         // get the database connection
  12.         $con = db_connect();
  13.  
  14.         // sql select statement
  15.         $sql = "SELECT * FROM customers WHERE customer_id = '" . $customerID . "'";
  16.  
  17.         // execute the query
  18.         $result = mysql_query($sql, $con);
  19.  
  20.         // check for a result 
  21.         if ($record = mysql_fetch_assoc($result)) {
  22.  
  23.             // create empty customer object
  24.             $customer = new Customer;
  25.  
  26.             // populate attributes
  27.             $customer->setCustomerID($customerID);
  28.             $customer->setFirstName($record['first_name']);
  29.             $customer->setLastName($record['last_name']);
  30.             $customer->setOrganization($record['organization']);
  31.             $customer->setPhone($record['phone']);
  32.             $customer->setFax($record['fax']);
  33.             $customer->setMobile($record['mobile']);
  34.             $customer->setEmail($record['email']);
  35.             $customer->setAddress1($record['address1']);
  36.             $customer->setAddress2($record['address2']);
  37.             $customer->setCity($record['city']);
  38.             $customer->setState($record['state']);
  39.             $customer->setCountry($record['country']);
  40.             $customer->setPostcode($record['postcode']);
  41.             $customer->setTier($record['tier']);
  42.         } // if
  43.  
  44.         // close the database connection
  45.         db_close($con);
  46.     } // if
  47.  
  48.     // return found ? populated customer : NULL
  49.     return $customer;
  50. } // getCustomer()

Anyway, I'm stumped! Help me please!

Finnian Burn
Jul 9 '08 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Finnian.

I see this sometimes when I mistype a single quote when I need a double quote or vice versa.

Also make sure you don't have an errant quote or backtick (`) somewhere where it doesn't belong.
Jul 9 '08 #2

P: 2
Heya, Finnian.

I see this sometimes when I mistype a single quote when I need a double quote or vice versa.

Also make sure you don't have an errant quote or backtick (`) somewhere where it doesn't belong.
I've only used single quotes for associative array access and no backticks anywhere. Any other ideas?

I've also cut-and-pasted the code that works ($customer->setBlah[...]) to the supplier method/object and simply renamed the object reference from $customer to $supplier in each instance it is used and still continue to get the error.

Could it be an actual bug in the parsing engine for PHP?

Finnian
Jul 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.