Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts

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

    PHP reports the following error:
    PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';'
    For this line:
    PHP Code:
    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?

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,393
    Thanks
    67
    Thanked 102 Times in 101 Posts
    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.

  • Users who have thanked myfayt for this post:

    Democrazy (09-17-2011)

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    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!

    EDIT: Thanks tangoforce.

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #7
    New Coder
    Join Date
    Aug 2011
    Location
    Melbourne, Brighton 3186
    Posts
    17
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Unless of course it is an included file and so the numbering goes right out of the window!

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by M1Creative View Post
    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.

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by M1Creative View Post
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #10
    New Coder
    Join Date
    Aug 2011
    Location
    Melbourne, Brighton 3186
    Posts
    17
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Thanks, I must look more carefully next time!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •