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

    Whats wrong with this line?

    What an Earth is wrong with this code?

    Code:
    $query = "select sizes from products where id='$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); if ($row == 0) {echo "";} else {echo "Small - $row['sizes']";}
    PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
    Last edited by Democrazy; 09-12-2011 at 03:54 PM.

  • #2
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    $row should have been $row['sizes']

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,332
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    else {echo "Small - $row['sizes']";}

    Remove those single quote marks so it looks like this: $row[sizes]

    Also see the link in my signature about quotes to learn about using them properly. When using an array and its key inside double quotes you don't use the single quotes.
    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
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by tangoforce View Post
    else {echo "Small - $row['sizes']";}

    Remove those single quote marks so it looks like this: $row[sizes]
    PHP Code:
    // Or
    else { echo "Small - {$row['sizes']}"; }
    // Or
    else { echo 'Small - ' $row['sizes']; } 
    It's best practice not to omit the quotes when referencing array keys.


  •  

    Posting Permissions

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