Jump to content


Photo

Error in code??


  • Please log in to reply
2 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 19 March 2006 - 12:02 PM

Can anyone see where the error in this code is:

foreach($food_categories as $key => $subarray)
{
echo "<h3>$key</h3>";
echo "<ul>";
foreach($subarray as $type)
{
echo "<input type='radio' name='interest'
value='$type'><b><img src="$type" width=100 height=100></b> (line 28)
<br>\n";
}
echo "</ul>";
}

The debugger is showing:

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Project\htdocs\catalogAccessories.inc on line 28

#2 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 19 March 2006 - 12:51 PM

[!--quoteo(post=356395:date=Mar 19 2006, 12:02 PM:name=OriginalSunny)--][div class=\'quotetop\']QUOTE(OriginalSunny @ Mar 19 2006, 12:02 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<b><img src="$type" width=100 height=100></b>
[/quote]

should be either \"$type\" or '$type', plus i'd recommend putting your width and height tags with ' or \" too.


#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 19 March 2006 - 12:54 PM

sure... where you're assigning your src, you're closing and reopening your string (double quotes) around your variable without concatonating. you need to do one of three things to fix it:

1) concatonate the string:
 echo "<input type='radio' name='interest'
value='$type'><b><img src=" . $type . " width='100' height='100'></b>
<br>\n";

2) escape the double quotes:
 echo "<input type='radio' name='interest'
value='$type'><b><img src=\"$type\" width='100' height='100'></b>
<br>\n";

3) use single quotes:
 echo "<input type='radio' name='interest'
value='$type'><b><img src='$type' width='100' height='100'></b>
<br>\n";

good luck
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users