How to detect a syntax error in PHP?

368 Views Asked by At

I have got a PHP syntax error called

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\playit2\rental_list.php on line 189

The line 189 is

$jsql_ae3 = mysql_query("select products.formats from products where products.id='$jrowa2['id']'") or die(mysql_error());
8

There are 8 best solutions below

1
On BEST ANSWER

With arrays and functions, you need to put curley braces:

$jsql_ae3 = mysql_query("select products.formats from products where products.id='{$jrowa2['id']}'") or die(mysql_error());
0
On

It should be -

"select products.formats from products where products.id='$jrowa2[id]'"
0
On

Change with this

$jsql_ae3 = mysql_query("select products.formats from products where products.id='$jrowa2[id]'") or die(mysql_error());
1
On

Using a PHP IDE with syntax highlighting such as NetBeans or PHPStorm.

In this particular case, you can insert a pair of brackets between the single quotes and the array access to fix this line:

$jsql_ae3 = mysql_query("select products.formats from products where products.id='{$jrowa2['id']}'") or die(mysql_error());
0
On

php_check_syntax should do the job for you. However this is only if you're running PHP >= 5.05. The first comment in the comments section will show you how to implement.

1
On
$jsql_ae3 = mysql_query("select products.formats from products where products.id='".$jrowa2['id']."'") or die(mysql_error());
0
On

When you use an array like this

$jrowa2['id']

inside a string with double quotes, PHP you do interpolation and try to interpret it, but, in this case, you can't use the simple quotes surrounding the key, you just have write the key (because it's already inside a string), then, you just use

$jrowa2[id]
0
On

Try this.

 $jsql_ae3 = mysql_query("select products.formats from products where products.id="$jrowa2['id']"") or die(mysql_error());

Hope this helps.