Re: Weird Syntax Error

From: Date: Fri, 14 Nov 2008 08:48:29 +0000
Subject: Re: Weird Syntax Error
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-283286@lists.php.net to get a copy of this message
-----Original Message----- From: Edgar da Silva (Fly2k) [mailto:silva.edgar@gmail.com] Sent: Thursday, November 13, 2008 9:39 AM To: Kyle Terry Cc: PHP General Mailing List Subject: Re: [PHP] Weird Syntax Error Try: $insert = "INSERT INTO release_file_upload (upl_file_name, upl_file_type, upl_file_size, upl_date, upl_by, upl_path, release_id) VALUES ('$filename', '{$_SESSION['upload']['type']}', '{$_SESSION['upload']['size']}', now(), '$username', '$path', '$release_id')"; 2008/11/13 Kyle Terry <kyle@kyleterry.com>:
    
I keep getting this syntax error on the following string...
syntax error unexpected T_ENCAPSED_AND_WHITESPACE expecting T_STRING
      
or
T_VARIABLE or T_NUM_STRING $insert = "INSERT INTO release_file_upload (upl_file_name,
      
upl_file_type,
upl_file_size, upl_date, upl_by, upl_path, release_id) VALUES
('$filename',
'$_SESSION['upload']['type']', '$_SESSION['upload']['size']', now(), '$username', '$path', '$release_id')";
      
Yup... I was just about to say--you need to wrap your array references with curly braces {}. Otherwise, I believe PHP will look for a primitive variable named $_SESSION, not an array whose indices are "upload" and "size". HTH, Todd Boyd Web Programmer You could also use the "." operator instead and quote using the quote method if you are using PDO. But this is a personal style I guess. -- Thodoris

« previous php.general (#283286) next »