PHP发票示例

在此问题中,您必须使用以下字段在html中创建表单:

  1. 产品(使用选择标签进行下拉)

  2. 产品数量

发票应包含以下内容:

  1. 序列号

  2. 产品名称

  3. 产品图片

  4. 产品费率

  5. 产品数量

  6. 折扣

  7. 净额(金额-折扣)

让我们开始解决这个问题:

要创建表单,请创建一个名为“ product.php”的文件,并编写以下代码:

HTML代码

<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>

现在使用url→'localhost / foldername / product.php'运行您的php文件

您将看到如下结果:

PHP中的发票示例-HTML表单

是时候开发票了。创建一个名为“ bill.php”的文件,并在其中添加以下代码:

带有HTML的PHP代码

<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>

此代码获取数量和产品(由用户选择)的值,根据用户选择的产品设置费率和折扣,计算总金额和净额。您可以用html形式的select标签替换product 1,product 2 ... product 4值

用户在选择产品并输入数量后点击“提交”按钮。它将进入“发票”页面,您将看到以下内容:

PHP中的发票示例-输出