What Is Unexpected T_Variable in PHP

What is unexpected T_VARIABLE in PHP?

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.

Parse error: syntax error, unexpected (T_VARIABLE)

Your code has some weird characters after the semicolon of this line:

$section1->execute();​
$section2->execute();​ //same for this line

If you look into a hex editor you see this:

24 73 65 63 74 69 6f 6e 31 2d 3e 65 78 65 63 75 74 65 28 29 3b e2 80 8b  
//^^^^^^^^This bit right here

//And it should look like this:
24 73 65 63 74 69 6f 6e 31 2d 3e 65 78 65 63 75 74 65 28 29 3b

See here:

Sample Image

(Yeah I know my circles aren't the nicest)

And this is how it should look like:

Sample Image


Solution?

Just write the statement new with your keyboard and your fingers.

syntax error, unexpected T_VARIABLE

There is no semicolon at the end of that instruction causing the error.

EDIT

Like RiverC pointed out, there is no semicolon at the end of the previous line!

require ("scripts/connect.php") 

EDIT

It seems you have no-semicolons whatsoever.

http://php.net/manual/en/language.basic-syntax.instruction-separation.php

As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of each statement.

Parse error: syntax error, unexpected T_VARIABLE on line 107

You're missing your concatenation operators:

 $sql="INSERT INTO " $table_name      "(confi
^^^^^ ^^^^^
HERE HERE

It should be

$sql="INSERT INTO " . $table_name . "(confi

PHP should also be warning you about $table_name=temp_members_db;.

You're missing quotes around your string value temp_members_db which is considered/treated as a constant if not quoted.

$table_name='temp_members_db';
  • FYI, you are also wide open to SQL injections.

PHP Syntax Error... unexpected T_VARIABLE?

The syntax highlighting shows you. Problem is the extra quote " here:

$query = "SELECT account_type,rank FROM users WHERE username= "$username";

Try:

$query = "SELECT account_type,rank FROM users WHERE username= '$username'";

PHP - Parse error: syntax error, unexpected T_VARIABLE in /home/a5547326/public_html/index.php on line 6

You missed semicolon after $data variable.

$data =  $browser[browser];

Unexpected T_VARIABLE error

Variables are not allowed here, properties must be initialized by constants in PHP:

[…] this initialization must be a constant value

[Source: php.net manual]

Use the constructor to intialize the value properly:

class session {
var $host;

function __construct() {
$this->host = $db_creds['host'];
}
}


Related Topics



Leave a reply



Submit