通过if else语句将值传递给数据库

时间:2018-03-04 15:35:46

标签: php

我的表格看起来像这样,这里我想通过从mepali_th_num形式获取和转换数字标记来发送尼泊尔主题数据库的等级,但是输入数字标记只是在转换成绩后才将'E'成绩发送到数据库。这段代码有什么问题,主要是if else部分。

<form class="form-horizontal" method="post">
<div class="box-body">
    <div class="form-group">
        <label for="nepali_th_num" class="col-sm-2 control-label">Nepali(TH)
        </label>
    <div class="col-sm-2">
    <input type="number" class="form-control" id="nepali_th_num" 
name="nepali_th_num" step="any" min="0">
    </div>
</div> 
<div class="box-footer">
    <button type="submit" name="btnSave" class="btn btn-
primary">Submit</button>
    <button type="reset" class="btn btn-info">Reset</button>
</div>            
</form>

我的php看起来像这样:

if (isset($_POST['btnSave'])){
    $marksdetails = new Marksdetails();   
    $marksdetails->set('nepali_th_num', $_POST['nepali_th_num']);
    $nep_per=((('nepali_th_num')*100)/75);
    if($nep_per>=90){
        $nepali_th_grade='A+';
    }elseif ($nep_per>=80 && $nep_per<90) {
        $nepali_th_grade='A';
    }elseif ($nep_per>=70 && $nep_per<80){
        $nepali_th_grade='B+';
    }elseif($nep_per>=60 && $nep_per<70) {
        $nepali_th_grade='B';
    }elseif($nep_per>=50 && $nep_per<60){
        $nepali_th_grade='C+';
    }elseif($nep_per>=40 && $nep_per<50){
        $nepali_th_grade='C';
    }elseif($nep_per>=30 or $nep_per<40){
        $nepali_th_grade='D+';
    }elseif($nep_per>=20 or $nep_per<30){
        $nepali_th_grade='D';
    }else{
        $nepali_th_grade='E';
    }
    $marksdetails->set('nepali_th_grade', $nepali_th_grade);
    $marksdetails->set('symbol_number', $symbolnumber);
    $marksdetails->set('student_name', $studentname);    
    $status=$marksdetails->checkDuplicate(); //to check duplicate and sql part 
    is in this 
}

0 个答案:

没有答案