PHP和MySQL Web开发—第一章学习

代码结构
php_project
|–orderform.html
|–processorder.php
|–freight.html

//processorder.php
<?php
    //提取表格数据
    $tireqty =$_POST['tireqty']?$_POST['tireqty']:0;
    $oilqty  =$_POST['oilqty']?$_POST['oilqty']:0;
    $sparkqty=$_POST['sparkqty']?$_POST['sparkqty']:0;
    $find=$_POST['find'];
    //定义单价
    define('TIREPRICE',100);
    define('OILPRICE',10);
    define('SPARKPRICE',4);
    //tireqty折扣
    if($tireqty<10)$discount=0;
    elseif ($tireqty>=10&&$tireqty<=49)$discount=5;
    elseif ($tireqty>=50&&$tireqty<=99)$discount=10;
    elseif ($tireqty>=100)$discount=15;
    //总数量
    $totalqty=0;
    $totalqty=$tireqty+$oilqty+$sparkqty;
    //总价
    $totalamount=0.00;
    $totalamount=$tireqty*TIREPRICE*(1-$discount*0.01)
                +$oilqty*OILPRICE
                +$sparkqty*SPARKPRICE;
    //税后总价
    $taxrate=0.10;
    $totalamount*=(1+$taxrate);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bob's Auto Parts - Order Results</title>
</head>
<body>
    <h1>Bob's Auto Parts</h1>
    <h2>Order Results</h2>
    <?php echo "<p>Order processed at ".date('H:i, jS F Y')."</p>"; ?>
    <?php
        if ($totalqty == 0){
            echo '<p style="color:#ff0000">';
            echo 'You did not order anything on the previous page!<br />';
            echo '</p>';
        }else{
            echo "<p>Your order is as follows: </p>";
            if($tireqty>0)echo htmlspecialchars($tireqty).' tires<br />';
            if($oilqty>0)echo htmlspecialchars($oilqty).' bottles of oil<br />';
            if($sparkqty>0)echo htmlspecialchars($sparkqty).' spark plugs<br />';
            echo "<p>Item ordered:"."$totalqty"."<br />";
            echo "Subtotal:$".number_format($totalamount,2)."<br />";
            echo "Total including tax:$".number_format($totalamount,2)."</p>";
        }
        //对多选处理
        switch ($find){
            case 'a':
                echo "<p>Regular customer.</p>";break;
            case 'b':
                echo "<p>Customer referred by TV advert.</p>";break;
            case 'c':
                echo "<p>Customer referred by phone directory.</p>";break;
            case 'd':
                echo "<p>Customer referred by word of mouth.</p>";break;
            default:
                echo "<p style='color: #ff0000'>We do not know this customer found us.</p>";break;
        }
    ?>
</body>
</html>
//orderform.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FORM</title>
</head>
<body>

<form action="processorder.php" method="post">
    <table style="border: 0px;">
        <tr style="background: #cccccc;">
            <td style="width: 150px;text-align: center;">Item</td>
            <td style="width: 15px;text-align: center;">Quantity</td>
        </tr>
        <tr>
            <td>Tires</td>
            <td><input type="text" name="tireqty" size="3" maxlength="3" /></td>
        </tr>
        <tr>
            <td>Oil</td>
            <td><input type="text" name="oilqty" size="3" maxlength="3" /></td>
        </tr>
        <tr>
            <td>Spark Plugs</td>
            <td><input type="text" name="sparkqty" size="3" maxlength="3"></td>
        </tr>
        <tr>
            <td>How did you find Bob's?</td>
            <td><select name="find">
                <option hidden></option>
                <option value="a">I'm a regular customer</option>
                <option value="b">TV advertising</option>
                <option value="c">Phone directory</option>
                <option value="d">Word of mouth</option>
            </select>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center"><input type="submit" value="SubmitOrder" /></td>
        </tr>
    </table>
</form>

<a href="freight.html">Freight</a>

</body>
</html>
//freight.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Bob's Auto Parts - Freight Costs</title>
</head>
<body>
    <table style="border: 0; padding: 3px;">
        <tr>
            <td style="background: #cccccc; text-align: center;">Distance</td>
            <td style="background: #cccccc; text-align: center;">Cost</td>
        </tr>

        <?php
            for($distance=50;$distance<=250;$distance+=50) {
                echo "<tr>
                        <td style='text-align: right;'>".$distance."</td>
                        <td style='text-align: right;'>".($distance/10)."</td>
                      </tr>\n";
            }
        ?>
    </table>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AQ_No_Happy

你的满意是我的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值