dongxing7318 2018-03-04 15:35
浏览 138
已采纳

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

My Form Look like this, here i wanted to send grade of Nepali subject database by taking and converting numeric marks from form mepali_th_num but what ever input numeric mark are it only send 'E' Grade to database after conversion of grade. What is wrong in this code mainly in if else part.

<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>

my php look like this:

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 
}
  • 写回答

1条回答 默认 最新

  • douxi1968 2018-03-04 15:46
    关注

    nepali_th_num in this line

    $nep_per=((('nepali_th_num')*100)/75); 
    

    is just a string, its not a variable containing something useful

    Try

    $nep_per=((($_POST['nepali_th_num'])*100)/75);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真