duanguane1670 2011-04-06 03:56
浏览 42

PHP函数和if / else语句

I am trying to write a script that includes if/else statements and functions. some background

  • $parts first character should have the letter "N"
  • $desc is suppose to be at least one character long
  • $price needs to be positive (0 or higher)

if all three of theses requirements are met then it should say "data accepted" if something is not met (one or all) the "Invalid...." needs to show.

can someone tell me what part of my script I should look at.

<?php
$parts = $_POST["parts"];
$desc  = $_POST["desc"];
$price = $_POST["price"];

$pa = substr($parts, 0, 1);
$de = strlen($desc);

if ($pa != "N")
 {echo "Invalid Part Number";}
else
 if ($de <= 1)
  {echo "Invalid Description Length";}
 else
  if ($price <= 0)
   {echo "Invalid Price";}
    else
     {echo "Data Accepted";}
?>
  • 写回答

5条回答 默认 最新

  • dongluan1743 2011-04-06 04:02
    关注

    The second if should be if($de==1) $de=1 will always return true.

    Also add semicolons after each statement.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?