...

View Full Version : Read over line 20 times, can't see a problem. WTF?!



Democrazy
09-17-2011, 02:56 PM
PHP reports the following error:

PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';'
For this line:

echo "Brand: "; $query = "select brand from products where id='$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); print $row['brand'];

I've read over the line 20 times and can't see a problem. Can you?

myfayt
09-17-2011, 03:23 PM
Doesn't appear to be on that line, it's most likely the line right before it. Post 5 lines, the two above and two below.

tangoforce
09-17-2011, 03:29 PM
PHPs line numbering in its errors is only for guidance. It usually means its near that area.. ish.

If you get line errors are the end of the script then its usually a braces issue.

Democrazy
09-17-2011, 03:31 PM
You were right mate. There were several errors above.

Why did it say line X, when it was lines above?

Thanks for the tip for the future bro! :thumbsup:

EDIT: Thanks tangoforce.

tangoforce
09-17-2011, 03:55 PM
Because it usually gives the line number after the last error. No idea why you'd have to ask the PHP developers why they've done that but it is similar with many languages.

Fou-Lu
09-18-2011, 02:10 AM
The line number is correct. The problem is that it cannot determine that a problem exists until its HIT that line number. Where the error exists can be lines before depending on exactly what the error is caused by. I've seen an error that was from missing "'s several lines earlier, but it doesn't consider it a problem until it hits the next opening " and finds that the next token isn't parsable. Generally speaking, its usually the line directly before.

M1Creative
09-18-2011, 05:10 AM
Unless of course it is an included file and so the numbering goes right out of the window!

Fou-Lu
09-18-2011, 07:56 AM
Unless of course it is an included file and so the numbering goes right out of the window!

Um, no.
The error will always tell you what file and line number the error has occurred with very few exceptions.

tangoforce
09-18-2011, 10:00 AM
Unless of course it is an included file and so the numbering goes right out of the window!

I've never encountered that - as Fou says PHP always tells you the filename.

The only time it does get a bit screwy is when using php code inside eval but even then it tells you what line in the eval'd code.

M1Creative
09-18-2011, 10:04 AM
Thanks, I must look more carefully next time!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum