Hi everyone, i'm new to PHP Builder as well as PHP in general! I'm currently developing my own PHP 'project' on a made up shop selling football shirts.
I have made a PHP page that displays all football shirts for sale. The football shirt data is being pulled (I hope thats the correct word) from a read file.
In one PHP page, I have created a table with all the football shirts being listed. Beside each football shirt, there is a selection box for the 'user' to select which shirt(s) they want to 'purchase'. At the bottom of the page I have a submit box. Once this submit box is clicked, a new PHP page appears showing which football shirts the 'user' wants to order.
It is on this page that I am having problems. I want to customise this page so that an invoice is created on it. For example, I want to list the selected items on the page and then have a total price of the shirt(s) ordered WITHOUT tax added and then below that a total price WITH tax added.
Below is the code I have for the page that displays all the football shirts available to order:
<html> <head> <title>Football Shirts 'R' Us</title> </head>
<body>
<body bgcolor="#339900">
<p> <font size=16, color=white><b><u><center>Football Shirts</center></u></b></p>
<form action="url here" method="post">
<br>
<table width=45%, border=1, align=center>
<tr>
<th> ID </th> <th> Football Shirt </th>
<th> Team </th> <th> Price </th> <th> Select </th>
</tr>
<tr><tr>
<?php
if(!($lines = file('read_shirts.txt')))
{echo 'ERROR: Unable to open file! </body></html>'; exit;}
foreach($lines as $theline) {
list($id, $shirt, $club, $price) = split('\|',$theline);
echo "
<tr>
<td>$id</td> <td> $shirt </td>
<td> $club </td> <td> $price </td> <td><center><input type='checkbox' name='$theline'></center></td>
</tr> ";
}
?>
</table>
<form>
<p><input type="submit" value="Submit">
</form>
<form>
<input type="reset" value="Reset">
</form>
</body> </html>
Note: where it says <form action="url here" method="post"> i've removed my local URL for the purpose of this thread.
Below is my PHP for the page that appears showing the shirt orders (where i'm having problems customising it):
<html> <head> <title>Football Shirts 'R' Us!</title> </head>
<body bgcolor="green">
<p> <font size=12, color=white><b><u><center>Your order with Football Shirts 'R' Us</center></u></b></p></font>
<p><font size=6, color=white>Hello, your order is as follows:</p></font>
<table> <tr> </tr>
<?php
$total="0";
foreach ($_POST as $varname => $varvalue) {
if(!($lines = file('read_shirts.txt')))
{echo 'ERROR: Unable to open file! </body></html>'; exit;}
foreach($lines as $theline)
{
list($id, $shirt, $club, $price) = split('\|',$theline);
if ($varname==$varvalue)
{
echo "
<br/><br/>
<tr>
<input type='hidden' name='itemcode' value=$id>
<td><align='center'> Item Number: $id </td>
<input type='hidden' name='description' value=$shirt>
<td><align='center'> Item Chosen: $shirt </td>
<input type='hidden' name='price' value=$club>
<td><align='center'> Price: $club </td>
<input type='hidden' name='price' value=$price>
<td><align='center'> Price: $price </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>";
?>
</table>
</body> </html>
When this page opens I get the following error message:
Your order with Football Shirts 'R' Us
Hello, your order is as follows:
Notice: Undefined variable: plusvat in /public_html/footballshirts/showvariables3.php on line 42
Total Excluding VAT: 0
Total Including VAT:
I appreciate any help anyone could give to a newbie!
Thanks!