473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

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
2 3217
pbmods
5,821 Expert 4TB
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
fburn
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

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

Similar topics

6
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After...
6
by: Ben Allen | last post by:
Hi, Im currently getting the error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in...
8
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine...
5
by: Anna MZ | last post by:
I am new to php and have written the following mysql code to enter the details of a new user in the admin subdomain of my website: $sql = "INSERT INTO 'users' ('userid', 'username', 'upassword')...
1
epots9
by: epots9 | last post by:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/xxx.php on line xxx I get that message when i try to run my...
3
by: basswhizz | last post by:
Hi everyone im a high school student and I'm having trouble with one of my projects could you please help!! I'm getting this error message. Parse error: syntax error, unexpected...
2
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString",...
15
by: micky125 | last post by:
Lo all, Ive been getting the error message Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/moneill/public_html/input.html...
68
mideastgirl
by: mideastgirl | last post by:
I keep getting this error and I cannot figure it out. My curly brackets are closed, and I am using the correct tags for <?php to open and ?> to close my code. Can someone please help me! Here is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.