在PHP中的Echo中检查单选按钮

时间:2017-11-05 11:58:19

标签: php

如何在echo方法中检查单选按钮?

<?php
      if(isset($_GET['sid'])){



          echo' 

    <div class="right_col" role="main">';
          $a=$_GET['sid'];
          $update = $obj->selectdata($a);

          foreach($update as $upd)
          {
               $upd['sname'];
          echo' 
        <h1 class="text-center">update student</h1>
        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-8">
                <form class="form-horizontal" action="dashboard.php?sid='.$upd['id'].'" method="POST" enctype="multipart/form-data">
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" value="'.$upd['sname'].'" name="sname" required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Father Name</label>
                        <input type="text" value="'.$upd['sfname'].'" name="sfname"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Email</label>
                        <input type="email" value="'.$upd['email'].'" name="semail"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Password</label>
                        <input type="password" name="spass" placeholder="Change Password"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Date Of Birth</label>
                        <input type="date" value="'.$upd['dob'].'" name="sdob"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Gender</label>

                    <div class="radio-inline">

                        <label><input type="radio" name="sgender" if($s_gender == Male){echo checked=checked}  value="Male" />Male</label>
                    </div>
                    <div class="radio-inline">
                    <label><input type="radio" name="sgender" if($s_gender == Female){echo checked=checked} value ="Female" />Female</label>
                    </div></div>





                    <div class="form-group">
                        <label>Contact</label>
                        <input type="text" name="scontact" value="'.$upd['contact'].'"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Address</label>
                        <input type="text" name="saddress"  value="'.$upd['address'].'" required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Photo</label>
                        <input type="file" name="spic"  required class="form-control"/>
                    </div>
                    <button type="submit" name="upt_form" class="btn btn-default">Submit</button>
                </form>
            </div>
        </div>';


          }
      }
      else {
      echo'

    <div class="right_col" role="main">
          <h1 class="text-center">add student</h1>
        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-8">
                <form class="form-horizontal" action="dashboard.php" method="POST" enctype="multipart/form-data">
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" name="sname" required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Father Name</label>
                        <input type="text" name="sfname"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Email</label>
                        <input type="email" name="semail"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Password</label>
                        <input type="password" name="spass"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Date Of Birth</label>
                        <input type="date" name="sdob"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Gender</label>

                    <div class="radio-inline">
                        <label><input type="radio" name="sgender" value="Male" required/>Male</label>
                    </div>
                    <div class="radio-inline">
                    <label><input type="radio" name="sgender" value ="Female"required />Female</label>
                    </div></div>
                    <div class="form-group">
                        <label>Contact</label>
                        <input type="text" name="scontact"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Address</label>
                        <input type="text" name="saddress"  required class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label>Photo</label>
                        <input type="file" name="spic"  required class="form-control"/>
                    </div>
                    <button type="submit" name="stu_form" class="btn btn-default">Submit</button>
                </form>
            </div>
        </div>';
      }
        ?>

2 个答案:

答案 0 :(得分:0)

像这样工作:

<input type="radio" '.($s_gender == Female ? 'checked="checked"' : "").' name="sgender"  value ="Female" />

答案 1 :(得分:0)

locate

使用此代码,然后让我知道它是否解决了您的问题,您必须以正确的方式将if和else用于您使用错误变量来获取性别值。