Error when creating a grand total of a basket
<p>I am getting an error regarding an undefined variable. However, the calculation is correct and it displays the grand total but the error still appears within the page - here is the error:</p>

<pre><code>Notice: Undefined variable: grand_total in
</code></pre>

<p>And here is my code:</p>

<pre><code>$line_cost = $product['price'] * $item['quantity'];
  $grand_total += $line_cost;

  ?&gt;

  &lt;tr&gt;
    &lt;td&gt;&lt;?=$product['common_name'];?&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type='text' name='quantity[]' value='&lt;?=$item['quantity'];?&gt;' size='2' /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;pound;&lt;?=number_format($line_cost, 2);?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;!---
    Notice the [] on the field name for quantity - this means it is an array
    The index of the array will start at 0 (i,e. the first product) and the second will be 1, etc...
  ---&gt;
  &lt;?php

}
?&gt;
  &lt;!-- Final row to put a button to recalculate --&gt;
  &lt;tr&gt;
    &lt;td colspan='3' align='center'&gt;
      &lt;input type='submit' name='recalc' value='Recalculate' /&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;pound;&lt;?=number_format($grand_total, 2);?&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
</code></pre>

<p></p>
