谁能帮忙做个PHP文件~
发布网友
发布时间:2022-04-24 14:09
我来回答
共1个回答
热心网友
时间:2023-10-15 18:36
//check.php
<?php
header("Content-type: text/html; charset=utf-8");//设置网页编码
define('STUDENT_ID', 20256); //定义学号;
define('STUDENT_NAME', 'michle_lee');//定义名字;
?>
<html>
<head>
<title>成绩判断</title>
</head>
<body>
<FORM METHOD='POST' ACTION="checked.php">
<h2><?php echo '学号为:<font color=red>' , STUDENT_ID , '</font><BR>' , '名字为:<font color=red>' , STUDENT_NAME , '</font>'?></h2>
<input type='text' value='请输入分数' id='scores' name='scores'><br>
<input type='submit' value="提交">
</FORM>
</body>
//======================================================================
//======================================================================
//======================================================================
//checked.php
<?php
header("Content-type: text/html; charset=utf-8");//设置编码
define('STUDENT_ID', 20256); //定义学号;
define('STUDENT_NAME', 'michle_lee');//定义名字;
//输出信息
echo '学号为:' , STUDENT_ID , '<BR>' , '名字为:' , STUDENT_NAME ;
//获取输入的分数的值(有可能是非法的);并且对获取的字符串两端去空格。
$raw_score = isset($_REQUEST['scores']) ? trim($_REQUEST['scores']) : 'empty' ;
//如果输入的值为'0';则需要特殊对待,因为下面用intval()函数进行处理后非法的结果返回的也是"0";
if( strval($raw_score) == '0' ){
$score = '0';
}else if (intval($raw_score) == 0){ //将获取的字符串转化为整型数字,如果是输入了非数字的字符则为"0";此时报参数非法错误
$score = 'illegal';
}else{
//在输入合法(是一个数字)的情况下符值;
$score = intval($raw_score);
}
//进行等级判断
if($score == 'illegal'){
$grade = "参数非法";
}else if(90 <= $score && $score <= 100){
$grade = '优秀';
}else if (80 <= $score && $score <= 90){
$grade = '良好';
}else if (70 <= $score && $score <= 80){
$grade = '中等';
}else if (60 <= $score && $score <= 70){
$grade = '及格';
}else if (0 <= $score && $score <= 60){
$grade = '不及格';
}else{
$grade = '超出范围';
}
//输出等级信息
echo '<br>成绩属于:<b><font color=red>' , $grade , '</font></b> 等级';
//输出导航
echo "<hr><a href='check.php' > 返回</a>"
?>