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,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    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.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 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
    •