...

View Full Version : Whats wrong with this line?



Democrazy
09-12-2011, 04:47 PM
What an Earth is wrong with this 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

Democrazy
09-12-2011, 05:06 PM
$row should have been $row['sizes']

tangoforce
09-12-2011, 05:08 PM
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.

Inigoesdr
09-12-2011, 06:19 PM
else {echo "Small - $row['sizes']";}

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



// 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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum