Q:

PHP Invoice Example

belongs to collection: PHP Database Programs

0

In this problem you have to make a form in html with the following fields:

  1. Product (use select tag to make a drop down)
  2. Quantity of product

Invoice should contain following:

  1. Serial number
  2. Product name
  3. Product Picture
  4. Product Rate
  5. Product Quantity
  6. Discount
  7. Amount
  8. Net Amount (Amount - Discount)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Let’s start to solve this problem:

To make your form make a file named "product.php" and write below code:

HTML code

<html>
	<form action="bill.php">
		<center>
		<table>
			<caption>
				<font color='blue' size='6'>Select Your Product</font>
			</caption>
			<br><br>
			
			<tr>
			<td>Choose Product:</td>
			<td>
				<select name=prd>
					<option>Product 1</option>
					<option>Product 2</option>
					<option>Product 3</option>
					<option>Product 4</option>
				</select>
			</td>

			<tr>
				<td>Quantity:</td>
				<td><input type=text name=qty></td>
			</tr>

			<tr>
				<td><input type=submit></td>
				<td><input type=reset></td>
			</tr>
			</table>
		<center>
	</form>
</html>

Now run your php file by using url → 'localhost/foldername/product.php'

You would see your result like this:

Invoice example in PHP - HTML form

It’s time to make the invoice. Make a file named "bill.php" and add following code in it:

PHP code with HTML

<html>
	<?php

		$prd=$_GET['prd'];
		$qty=$_GET['qty'];
		$rate=0;
		$img="";
		
		if($prd=="Product 1")
		{
			$rate=400;
			$img='p1.png';
		}
		else if($prd=="Product 2")
		{
			$rate=150;
			$img='p2.jpg';
		}
		else if($prd=="Product 3")
		{
			$rate=50;
			$img='p3.jpg';
		}
		else if($prd=="Product 4")
		{
			$rate=30;
			$img='p4.png';
		}
		$amt=$rate*$qty;
		$dis=$amt*5/100;
		$na=$amt-$dis;
		
	?>
	<center>
	<table border=1 width=70%>
		<caption>
			<font color='blue' size='8'> Invoice</font>
		</caption>
		<br><br>

		<tr>
			<th>S.No</th>
			<th>Description</th>
			<th>Rate</th>
			<th>Qty</th>
			<th>Amount</th>
			<th>Discount</th>
			<th>Net Amount</th>
		</tr>
		
		<tr>
			<td>1</td>
			<td>
				<?php echo "$prd<br><img src=$img width=60 height=60>";?>
			</td>
			<td>
				<?php echo "$rate";?>
			</td>
			<td>
				<?php echo "$qty";?>
			</td>
			<td>
				<?php echo "$amt";?>
			</td>
			<td>
				<?php echo "$dis";?>
			</td>
			<td>
				<?php echo "$na";?>
			</td>
		</tr>
	</table>
	</center>
</html>

This code fetches the value of quantity and product (chosen by user), sets a rate and discount according to the product choose by user and calculates the total amount and net amount. You can replace the product 1, product 2 ... product 4 values in html form select tag.

As the user hits the submit button after choosing the product and entering the quantity. It will land on Invoice page and you would see like this:

Invoice example in PHP - Output

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Code to Insert Data in MySql... >>
<< PHP PDO Inserting data into tables...