两个网页,第一个是html 填写简单表单,确定苹果桔子的数量。第二个是php,用来统计表单中苹果,桔子的总价格。第一次写php大家多包涵。问题太简单,惭愧中抱怨!!!!   0<a<5 php 里面居然要分开写 (a>0) && (a<5) 实在啰嗦。
第一个html代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<form id="form1" name="form1" method="post" action="processorder.php" >
  <p>客户名:
    <input name="name" type="text" />
  </p>
  <p>
    桔子(斤):  
      <input name="orangeqty" type="text" />
  (5斤以下1元/斤,5-20斤0.8元/斤,20斤以上0.7元每斤)</p>
  <p>苹果(斤): 
    <input name="appleqty" type="text" />
    (5斤以下2元/斤,5-20斤1.8元/斤,20斤以上1.5元每斤)
  <p>
   是否打印发票:  
  <select name="sex"><br />
    <option>是</option>
    <option>否</option>
  </select> 
  <p>
  <input name="submit" type="submit"  value="提交订单"/>
  </p>
</form>
</body>
</html>第二个php 代码如下:<?php
date_default_timezone_set('Asia/Shanghai');
$appleqty=$_POST['appleqty'];
$orangeqty=$_POST['orangeqty'];
$name=$_POST['name'];echo("客户名:").$name."<p/>";
echo ("订单时间:"). date("y年m月d日 h小时 m分钟"). "<p/>" ;//判断是否有下订单
if ($appleqty==0 and  $orangeqty==0) {
echo("您没有下订单。");
}//判断apple和oranger的价格
if (($orangeqty<5) && (orangeqty>0)) {
$orangeprice=1;
}elseif (($orangeqty<=20) && ($orangeqty>=5)) {
$orangeprice=0.8;
}elseif ($orangeprice>20) {
$orangeprice=0.7;
}

if (($appleqty<5) && ($appleqty>0) ) {
$appleprice=2;
}elseif (($appleqty<=20) &&( $appleqty<=5) ) {
$appleprice=1.8;
}elseif ($appleprice>20) {
$appleprice=1.5;
}
//计算apple和oranger的总价格
$appletotal=$appleqty*$appleprice;
$orangetotal=$orangeqty*$orangeprice;
$total=$appletotal+$orangetotal;

echo("您已经订购").$orangeqty."斤桔子和".$appleqty."斤苹果,合计".$total."元。";
?>

解决方案 »

  1.   

    //判断apple和oranger的价格 if (($orangeqty <5) && (orangeqty>0)) { 
    漏掉了一个$
    以后请把错误信息贴上  方便别人看
      

  2.   

    elseif ($appleprice>20) {
    $appleprice=1.5;

    -_-!!!
    红色部分应该是$appleqty吧
      

  3.   

    谢谢.根据2位指点,已近调试正确。我刚用php,目前在dreamweaver里面写html代码,在zend 5.51内写php文件,后台运行wamp。调试通过dreamweaver 的f12键 ,没看到特别的错误提示就忘记写调试过程了。二位添麻烦不好意思。谢谢二位!