dongqi8114 2015-07-24 04:03
浏览 293

PHP简单发票收据

i want to make a simple receipt from a fast food JollyMenu.php

<form action="showReceipt.php" method="POST">
<table >
<tr><td>Transaction ID <input type="text" name="txtID"> <?php echo date("m / d / Y");?></td></tr>
<tr><td><h2>Your Order:</h2></td></tr>
<tr><td><input  type="checkbox"  name="cbItem[]" value="Chicken Joy"> Chicken Joy (PhP 90.00)</td> <td>Quantity <input type="text" name="txtQty[]"></td></tr>
<tr><td><input  type="checkbox" name="cbItem[]" value="Jolly Spaghetti"> Jolly Spaghetti (PhP 50.00)</td> <td>Quantity <input type="text" name="txtQty[]"></td></tr>
<tr><td><input type="checkbox" name="cbItem[]" value="Yum Burger"> Yum Burger (PhP 29.00)</td> <td>Quantity <input type="text" name="txtQty[]"></td></tr>
<tr><td><input type="checkbox" name="cbItem[]" value="Jolly Twirls"> Jolly Twirls (PhP 25.00)</td> <td>Quantity <input type="text" name="txtQty[]"></td></tr>
<tr><td><input type="checkbox" name="cbItem[]" value="Big Champ"> Big Champ (PhP 120.00)</td> <td>Quantity <input type="text" name="txtQty[]"></td></tr>
<tr><td>Amount Given: <input type="text" name="txtAmount"></td> <td><input type="submit" name="btnGen" value="Generate Receipt">  <input type="reset" value="Clear">


</table>
</form>

ShowReceipt.php

<html>
<body>


<?php
        
error_reporting(0); 
echo '<p align="center">JollyBee Food Corporation</br>
        1/F Kalentong cor. Shaw Blvd. Mandaluyong City 550</br>
            </br></p></br>';

$item=$_POST['cbItem'];
$qty=$_POST['txtQty'];
    
if(isset($_POST['btnGen'])){        
{
    
foreach($item as $selected)
{   
            
    if($selected=='Chicken Joy')
    {
        $price = 90.00;
        $total += 90.00;
        
    }
    else if($selected=='Jolly Spaghetti')
    {
        $price = 50.00;
$total += 90.00;
        
    }
    else if($selected=='Yum Burger')
    {
        $price = 29.00;
        $total += 29.00;
    }
    else if($selected=='Jolly Twirls')
    {
        $price = 25.00;
        $total += 25.00;
    }
    else if($selected =='Big Champ')
    {
        $price = 120.00;
        $total += 120.00;
    }
                    
echo $selected.$_POST["txtQty"][$i].'<br>';
echo $price.'<br>';
    
}
}
}


echo $total;
                                                
?>

</body>
</html>

and I need to get also need to get the value of the textboxes for quantity to multiply to the number of items has been choose..how can I get the value of textboxes to run in that for each loop.?

</div>
  • 写回答

1条回答 默认 最新

  • duangewu5234 2015-07-24 04:41
    关注

    I would recommend using unique product ids for each item and qty field. The problem is that the cbItem and txtQty keys will only match up correctly when ALL items are checked. The quickest/easiest solution as I see it would be to key each txtQty field name on the associated cbItem VALUE. So the FIRST

    <input type="text" name="txtQty[]">
    

    would become:

    <input type="text" name="txtQty[Chicken Joy]">
    

    Then in your PHP code, replace each set of:

    $price = 90.00;
    $total += 90.00;
    

    with:

    $price = 90;
    $total += ($price * max($qty[$selected], 1)); // ensure at least qty of 1
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀