为了账号安全,请及时绑定邮箱和手机立即绑定

PHP判断学习成绩,多重if判断嵌套继续懵逼,求助人为乐的牛

<!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>
    <style type="text/css">
        body{
            font-size:18px;
        }
    </style>
</head>
<body>
        <?php
            $str='';
        if(isset($_GET['1name'])) {
            $name = $_GET['1name'];
        }
        if (empty($name)) {
            $str = "姓名不能为空!";
            return false;
            }
        if (is_numeric($name)) {
            $str = "姓名不能为数字";
            return false;
        }
        if (isset($_GET['1score'])) {
            $score = $_GET['1score'];
        }
        if (empty($score)) {
            $str = "成绩不能为空";
            return false;
        }
        if (is_numeric($score)) {
            if ($score < 0 || $score > 100) {
                $str = "成绩虚假,son of a bitch";
            } else {
                switch ((integer)($score / 10))//0,1,2,3,...,10
                {
                    case 10:
                        $str = 'A+';
                        break;
                    case 9:
                        $str = 'A';
                        break;
                    case 8:
                        $str = 'B';
                        break;
                    case 7:
                        $str = 'C';
                        break;
                    case 6:
                        $str = 'D';
                        break;
                    default:
                        $str = 'fail';
                        break;
                }
            }
        }
        ?>
<form action="#" method="get">
    请输入学生的姓名:
    <input type="text"  name="1name" value="<?php if(!empty($_POST["lname"])){ echo $_GET["lname"] ;} ?>" /><br />
    请输入学生的成绩:
    <input type="text"  name="1score" value="<?php if(!empty($_POST["lscore"])){echo $_GET["lscore"];} ?>" /><br />
    <input type="submit" value="提交" />
</form>
        <?php
        echo $str;
        ?>
</body>
</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>
    <style type="text/css">
        body{
            font-size:18px;
        }
    </style>
</head>
<body>
        <?php
            $str='';
        if(isset($_GET['1name'])) {
            $name = $_GET['1name'];
            if (empty($name)) {
                 $str = "姓名不能为空!";}else{
                if (is_numeric($name)) {
                     $str = "姓名不能为数字";}else{
                    if (isset($_GET['lscore'])) {
                        $score = $_GET['lscore'];}
                        if (empty($score)) {
                             $str = "成绩不能为空";}else{
                            if (is_numeric($score)) {
                                if ($score < 0 || $score > 100) {
                                     $str = "成绩虚假,son of a bitch";
                                } else {
                                    switch ((integer)($score / 10))//0,1,2,3,...,10
                                    {
                                        case 10:
                                            $str = 'A+';
                                            break;
                                        case 9:
                                            $str = 'A';
                                            break;
                                        case 8:
                                            $str = 'B';
                                            break;
                                        case 7:
                                            $str = 'C';
                                            break;
                                        case 6:
                                            $str = 'D';
                                            break;
                                        default:
                                            $str = 'fail';
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        ?>
<form action="#" method="get">
    请输入学生的姓名:
    <input type="text"  name="1name" value="<?php if(!empty($_POST["lname"])){ echo $_GET["lname"] ;} ?>" /><br />
    请输入学生的成绩:
    <input type="text"  name="1score" value="<?php if(!empty($_POST["lscore"])){echo $_GET["lscore"];} ?>" /><br />
    <input type="submit" value="提交" />
</form>
        <?php
        echo $str;
        ?>
</body>
</html>

无法判断成绩;

http://www.imooc.com/wenda/detail/333114

原问题


正在回答

2 回答

 $score = $_GET['lscore'];//这里应该是1不是L吧!最下面那也是。这种代码问题就自己好好检查。


0 回复 有任何疑惑可以回复我~
#1

侠客岛的含笑 提问者

不好意思,我在慕课网php群里问的是他们说我的判断冲突,我找了半天没找到,没法了,只好到处问,而且我的phpstrom字体1和l和相似
2016-10-28 回复 有任何疑惑可以回复我~

这种简单的问题,就学着自己排查,不是所有人都有时间帮你排查的,很多人只是看一眼,猜测一下问题所在,反而给你带错方向。

0 回复 有任何疑惑可以回复我~
#1

侠客岛的含笑 提问者

我逻辑思维不是很好,而且我这个人是很多疑的,所以,我感觉我的思路也是有问题的。写个几层嵌套我就晕了
2016-10-28 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

PHP判断学习成绩,多重if判断嵌套继续懵逼,求助人为乐的牛

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信