Hi there
Im trying to sort out some code for a simple ordering process.
I have a php form that lists the items from a .txt file with checkboxes where the user can then select items. However on the next form I cant get the form to display the itesm selected and their prices to calculate VAT and total cost etc.
Im getting the following error when I try to process this second form:
Notice: Undefined variable: plusvat in /nas/........
Heres the form I'm trying to pull the data from:
<form action="purchases2.php" method="post">
<table border="2" cellpadding="5" cellspacing="5" width="50%">
<tr>
<th> Image </th>
<th> Description </th> <th> Sport </th> <th> Price </th> <th> Please Select </th>
</tr>
<?php
if(!($lines = file('itemlist.txt')))
{echo 'ERROR: Unable to open file! </body></html>'; exit;}
foreach($lines as $theline)
{
list($itemid, $sport, $description, $price, $image)
= split('\|',$theline);
echo "
<tr>
<td><img src='$image' width='45' height='45'></td> <td> $description </td> <td> $sport </td>
<td> $price </td> <td> <input type='checkbox' name='$theline' </td>
</tr> ";
}
?>
and here is the php code i currently have that I want to retrieve the items price and description from a .txt file and manipulate the data to get VAT prices etc.
<form action="ordersummary2.php" method="post">
<?php
$total="0";
foreach ($_POST as $varname => $varvalue) {
if(!($lines = file('itemlist.txt')))
{echo 'ERROR: Unable to open file! </body></html>'; exit;}
foreach($lines as $theline)
{
list($itemid, $sport, $description, $price, $image) = split('\|',$theline);
if ($varname==$varvalue)
{
echo "
<br/><br/>
<tr>
<input type='hidden' name='itemcode' value=$itemid>
<td><align='center'> Item Number: $itemid </td>
<input type='hidden' name='description' value=$description>
<td><align='center'> Item Chosen: $desciption </td>
<input type='hidden' name='price' value=$price>
<td><align='center'> Price: $price </td>
<td><align='center'><img src='$image' width='70' height='70'></td>
</tr>";
$total=$total+$price;
$plusvat=number_format($total*1.175,2);
}}}
echo "
<br>
<tr> <td aliign='left'> Total Excluding VAT: </td> <td> $total </td> </tr>
<br>
<tr> <td align='left'> Total Including VAT: </td> <td> $plusvat </td> </tr>";
?>
Can anyone spot any obvious mistakes I have made
Thanks in advnace and sorry if i have included irrelevant code!