在while循环中定义变量时意外的T_ECHO

I've been looking at this for hours and am getting ready to give up. I'm getting an unexpected 'echo' (T_ECHO) error. I know this means I have misused/misplaced echo so I have tried numerous combinations of quotes to figure it out, but alas I have failed. Here is my code:

while($row = mysqli_fetch_array($result)){
$img = '<img src="/upload/"' . echo $row['image'] . '"/>';
printf('<li id="page_%s">%s</li>', $row['Item_ID'], $img);
}

Please help!

Echo isn't a function, it's a language construct and can't return anything. Instead of using echo, you would just concatenate directly. Also, remember to use htmlspecialchars() around any arbitrary data to ensure you're generating valid HTML. And finally, you have extra quotes in your HTML attribute for src. Try this:

$img = '<img src="/upload/' . htmlspecialchars($row['image']) . '" />';

If you want to make this nice and clean, consider a template engine such as Smarty.