Recent Posts

How to solve: Parse error: syntax error, unexpected T_VARIABLE

Possible scenario
I can't seem to find where my code has went wrong. Here is my full error:
Parse error: syntax error, unexpected T_VARIABLE on line x
what i am trying
$sql = 'SELECT * FROM dealer WHERE id="'$id.'"';
Answer
Parse error: A problem with the syntax of your program, such as leaving a semicolon off of the end of a statement or in like in above case missing . operator . The interpreter stops running your program when it encounters a parse error.
In simple word this is a syntax error, meaning that there is something in your code stopping it from being parsed correctly and therefore run.
What you should do is check carefully at the lines around where the error is for any simple mistakes
That error message means that in line x of the file, the PHP interpreter was expecting to see an open parenthesis but instead, it encountered something called T_VARIABLE. That T_VARIABLE thing is called a token. It's the PHP interpreter's way of expressing different fundamental parts of programs. When the interpreter reads in a program, it translates what you've written into a list of tokens. Wherever you put a variable in your program, there is aT_VARIABLE token in the interpreter's list.
so make sure you enable at least E_PARSE in your php.ini. Parse errors should not exist in production scripts.
i always recommended to while coding
error_reporting(E_ALL);
Also a good idea to use IDE which will let you know parse error while typing. You can sue
  1. NetBeans (fine peace of beauty, free)(imho its best)
  2. PhpStorm (Uncle Gordon love this :P , paid)
  3. Eclipse (beauty and the beast free)

No comments:

Post a Comment