Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If this is PHP and you are trying to assign a string to a variable, there should be quotes arround the string.</p> <p>Here, this specific portion of code is causing an error :</p> <pre><code>$img_attributes= style='max </code></pre> <p>There should be some kind of quote after the first = sign.</p> <p><br> Something like this should work much better, for instance :</p> <pre><code>$img_attributes= 'style="max-height: 100px; max-width: 100px"' . ' alt="' . $product['product_name'] . '"'; </code></pre> <hr> <p>As a sidenote : maybe some kind of escaping could be helpful, for the <code>$product['product_name']</code> part ? to make sure it doesn't contain any HTML that would break your markup. <br>See <a href="http://www.php.net/htmlspecialchars" rel="nofollow noreferrer"><code>htmlspecialchars</code></a>, for instance.</p> <p>For instance, if your product name is initialized this way :</p> <pre><code>$product['product_name'] = 'my mega "product"'; </code></pre> <p>Then, using the portion of code I posted earlier will get you this output :</p> <pre><code>style="max-height: 100px; max-width: 100px" alt="my mega "product"" </code></pre> <p>Which is not that nice...</p> <p>Using <code>htmlspecialchars</code>, like this :</p> <pre><code>$img_attributes= 'style="max-height: 100px; max-width: 100px"' . ' alt="' . htmlspecialchars($product['product_name']) . '"'; </code></pre> <p>The output would become :</p> <pre><code>style="max-height: 100px; max-width: 100px" alt="my mega &amp;quot;product&amp;quot;" </code></pre> <p>Which, at least, is a portion of valid-HTML :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload