php - Unexpected T_ECHO while defining variable inside of while loop -


i've been looking @ hours , getting ready give up. i'm getting unexpected 'echo' (t_echo) error. know means have misused/misplaced echo have tried numerous combinations of quotes figure out, alas have failed. here 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 function, it's language construct , can't return anything. instead of using echo, concatenate directly. also, remember use htmlspecialchars() around arbitrary data ensure you're generating valid html. , finally, have quotes in html attribute src. try this:

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

if want make nice , clean, consider template engine such smarty.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -