问题遇到的现象和发生背景
怎么在下面性别的单选按钮写if语句,如果性别是男的,就在男的单选按钮上加checked属性,如果不是,就在女的单选按钮上加checked属性。
问题相关代码,请勿粘贴截图
<div class="well">
<label>联系人名称</label>
<input type="text" name="cname" id="cname" class="input-xlarge" value="<?php echo $admin_array[$tbCname];?>" style="width: 70%;" />
<label>联系人电话</label>
<input type="text" name="ctel" id="ctel" class="input-xlarge" value="<?php echo $admin_array[$tbCtel];?>" style="width: 70%;" />
<label>联系人地址</label>
<input type="text" name="caddress" id="caddress" class="input-xlarge" value="<?php echo $admin_array[$tbCaddress];?>" style="width: 70%;" />
<label>性别</label>
<input type="radio" name="csex" value="男" checked/>男
<input type="radio" name="csex" value="女" />女
<label>联系人类别</label>
<select name="ctypeid" id="ctypeid">
<option value="">|-请选择联系人类别</option>
<?php
//定义SQL语句,查询联系人类别表中的所有内容
$ntsql="select * from $tbContactstype";
//在数据库中查询SQL语句,将查询结果保存到query_result中
$query_result=$db->query($ntsql);
while($onecatearray=$db->getarray($query_result)){
echo"<option value='".$onecatearray[$tbCtypeid]."'";
if($onecatearray[$tbCtypeid]==$admin_array[$tbCtypeid])
{
echo "selected";
}
echo"> |-".$onecatearray[$tbCtypename]."</option>";
}
?>
</div>
<?php
@require_once"../include/function.php";
//1.取得表单中传递过来的联系人类别名称和联系人类别编号
$temp_ctypeid=$_POST['id'];
$temp_ctypename=$_POST['ctypename'];
//2.判断联系人类别表是否已经有同名类别存在
//设置sql语句。到tbcontactstype表中查找有没有同名账号
$sql="select*from $tbContactstype where $tbCtypename='$temp_ctypename'";
//通过getcount函数执行查询,执行结果返回resultnums变量
$resultnums=$db->getcount($sql);
//如果$resultnums的值补位0说明类别已经存在
if($resultnums!=0){
//给出提示
echo"<script>alert('对不起,类别已存在');</script>";
echo"<script>window.history.go(-1);</script>";
}
elseif($temp_ctypename==""){
echo"<script>alert('请将表单填写完整!');</script>";
echo"<script>window.history.go(-1);</script>";
}
else{
//3.给出update语句,完成类别的修改
$contacttypesql="update $tbContactstype
set $tbCtypename='$temp_ctypename' where $tbCtypeid='$temp_ctypeid'";
$query_result=$db->query($contacttypesql);
//通过判断$query_result变量的值,来确定是否添加成功,如果值不为0,说明已成功,否则就是失败了
if($query_result){
echo"<script>alert('类别修改成功!');</script>";
echo"<script>window.location.href='contacttype_list.php';</script>";
}
else{
echo"<script>alert('类别修改失败!');</script>";
echo"<script>window.history.go(-1);</script>";
}
}
?>
//定义数据库表名和字段
//----------------contactstype表-----------------------------------------
$tbContactstype="contactstype";//表名
$tbCtypeid="ctypeid";
$tbCtypename="ctypename";
//------------------------------------------------------------------------
//----------------contacts表-----------------------------------------
$tbContacts="contacts";//表名
$tbCid="cid";
$tbCname="cname";
$tbCsex="csex";
$tbCtel="ctel";
$tbCaddress="caddress";
$tbCtypeid="ctypeid";
//------------------------------------------------------------------------
//----------------users表-----------------------------------------
$tbUsers="users";//表名
$tbUserid="userid";
$tbUsername="username";
$tbUserpwd="userpwd";
$tbUserquestion="userquestion";
$tbUseranswer="useranswer";
//------------------------------------------------------------------------