unexpected T_STRING on first line of code - php

I have been getting an error saying unexpected T_STRING on line 2 of this script:
<? php
session_start();
$incidentKey = $_SESSION['incidentKey'];
$incidentDetailsQuery = mysql_query("SELECT * FROM incidents WHERE incidentKey='".$incidentKey."'");
while ($incidentDetails = mysql_fetch_assoc($incidentDetailsQuery);
?>
And despite looking through the forum heaps, I have had no luck. This was even coming up as an error saying unexpected T_STRING on line 2 when I the code started like this:
<? php
$incidentKey = $_SESSION['incidentKey'];
etc.....
I've gone through all other includes and couldn't find any missing terminators leading up to this script. Can anyone think why else I would be getting this error?

Remove the space in
<? php
to make it
<?php

Related

PHP Parse error: syntax error, unexpected T_STRING

I'm working in OsCommerece and getting this up in my error log
PHP Parse error: syntax error, unexpected T_STRING in public_html/includes/classes/seo.class.php(2206) : eval()'d code on line 1
Maybe just remove the <?php, ?> tags, as seo.class.php seems to run the input through eval()
mixed eval(string $code)
The code mustn't be wrapped in opening and closing PHP
tags...

IPBoard Error Parse error: syntax error, unexpected T_STRING

I have been having this error with IPBoard when trying to install a skin/theme. I get this message when I apply it to my forum:
Parse error: syntax error, unexpected T_STRING in /home/a7952789/public_html/forum/cache/skin_cache/cacheid_7/skin_global.php on line 83
So I decided to check It out I re-parsed it and it said no errors in CODE. here is the exact line of code:
$this->functionData['globalTemplate'][$count_3b65c7bc63b10c5a7f84294eb9b75dd2]['array_header_items'] = $array header_items;
$array header_items doesn't make any sense. It might be a typo for $array_header_items, although it's hard to guess what it is supposed to be.

PHP T_STRING Error in Header Location

I keep getting this error..
PHP Parse error: syntax error, unexpected T_STRING in C:\inetpub\storeboard.com\oauth\callback.php on line 39
What am I doing wrong with this line of code? This is line 39
header('Location: ./save_twitter_tokens.php?nToken='.$access_token["oauth_token"].'&nSecret='.$access_token["oauth_token_secret"].');
maybe this will work:
header('Location: ./save_twitter_tokens.php?nToken='.$access_token["oauth_token"].'&nSecret='.$access_token["oauth_token_secret"]);
You can see it in the syntax highlighting of the code you posted. The last string doesn't get closed. Remove the .' at the end.

PHP error when attempting to print variables within an echo using heredoc

When I try to do this:
var $example = "Example";
echo <<<EOT
<p>$example</p>
EOT;
I get this error:
Parse error: syntax error, unexpected
T_VAR in ..... on line ...
What is going on here?? To my knowledge this should work.
I'm using PHP 5.3.5.
The var keyword on the first line is for declaring variables in classes only. Leave it out.
remove the word var.
see http://www.php.net/manual/en/language.variables.basics.php
There is no keyword var in PHP. Not in PHP5 anyway - it's only accepted due to backward compatibility, and is used to define class variables.
D'oh. Removing the 'var' keyword fixed it. Thanks for the input guys!
Unfortunately however it didn't solve my actual problem. See here:
$param = array_merge($_REQUEST, $_FILES, $_COOKIE);
$param['example'] = "example";
example();
function example()
{
global $param;
echo <<<EOT
<p>$param['example']</p>
EOT;
return;
}
This time the complaint is:
Parse error: syntax error, unexpected
T_ENCAPSED_AND_WHITESPACE, expecting
T_STRING or T_VARIABLE or T_NUM_STRING
in ..... on line ...
Again, what is going on here?

What is unexpected T_VARIABLE in PHP?

I get this PHP error:
Parse error: syntax error, unexpected
T_VARIABLE
From this line:
$list[$i][$docinfo['attrs']['#groupby']] = $docinfo['attrs']['#count'];
Is there anything wrong with this line?
There might be a semicolon or bracket missing a line before your pasted line.
It seems fine to me; every string is allowed as an array index.
It could be some other line as well. PHP is not always that exact.
Probably you are just missing a semicolon on previous line.
How to reproduce this error, put this in a file called a.php:
<?php
$a = 5
$b = 7; // Error happens here.
print $b;
?>
Run it:
eric#dev ~ $ php a.php
PHP Parse error: syntax error, unexpected T_VARIABLE in
/home/el/code/a.php on line 3
Explanation:
The PHP parser converts your program to a series of tokens. A T_VARIABLE is a Token of type VARIABLE. When the parser processes tokens, it tries to make sense of them, and throws errors if it receives a variable where none is allowed.
In the simple case above with variable $b, the parser tried to process this:
$a = 5 $b = 7;
The PHP parser looks at the $b after the 5 and says "that is unexpected".
In my case it was an issue of the PHP version.
The .phar file I was using was not compatible with PHP 5.3.9. Switching interpreter to PHP 7 did fix it.

Categories