Monday, December 26, 2016

Parse error: syntax error, unexpected '=' in path/to/filename.php on line

Parse error: syntax error, unexpected '=' in path/to/filename.php on line xxx

It is usual to get cryptic error messages when executing php code. It is not intentional but essentially it tells us that the code is not right in just about the indicated area. 

Take a look at the sentence given below.

variable ="select item from my_images where id =$key";

We will have to look a little ahead and a little behind the "=" symbol, in this case.

At first glance, everything seems to be in order. This is true, especially, when one is in an agitated condition.

But, if you analyse the php program statement carefully, you will notice that you have forgotten to place the mandatory $ sign, which indicates that the word is a php variable.

This is a common error in php. 

Place the $ sign before the variable name and all things seem okay.

As to the question of why you need the $ in the first place, it is to declare that this specific word will store some information within.

It provides more clarity to the code and the habit is continued from other programs such as Perl, where a $ is prefixed to define a variable as well.
Post a Comment

Why should I not take revenge?

This is what we do and have been doing since we have known man. Revenge seems to be a natural response to injustice that seems to target us... Registered & Protected DWYE-NHTO-NBNH-7FFM