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:
Notice: Undefined variable: grand_total in
And here is my code:
$line_cost = $product['price'] * $item['quantity'];
$grand_total += $line_cost;
?>
<tr>
<td><?=$product['common_name'];?></td>
<td><input type='text' name='quantity[]' value='<?=$item['quantity'];?>' size='2' /></td>
<td>£<?=number_format($line_cost, 2);?></td>
</tr>
<!---
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...
--->
<?php
}
?>
<!-- Final row to put a button to recalculate -->
<tr>
<td colspan='3' align='center'>
<input type='submit' name='recalc' value='Recalculate' />
</td>
</tr>
<tr>
<td>£<?=number_format($grand_total, 2);?></td>
</tr>
</table>
It seems
$grand_totalvariable not defined above.Also you can change error reporting to not show notice/warning with error_reporting()