第一种方式找到该条信息的主键值,通过sql语句查询到该条数据,通过数组方式显示在INPUT的value值里
<body> <?php $yhm = $_GET["ids"]; require_once "./lib/DBDA.class.php"; $db = new DBDA(); $sql = "select * from user where uid='{$yhm}'"; $arr = $db->query($sql); ?> <form> <div>用户名:<input type="text" name="yhm" value="<?php echo $arr[0][0] ?>" /></div> <div>密码:<input type="text" name="pwd" value="<?php echo $arr[0][1] ?>" /></div> <div>姓名:<input type="text" name="uname" value="<?php echo $arr[0][2] ?>"/></div> <div>性别:<input type="radio" name="sex" value="1" <?php echo $arr[0][3]?"checked=checked":"" ?>/>男 <input type="radio" name="sex" value="0" <?php echo $arr[0][3]?"":"checked=checked" ?> />女</div> <div>生日:<input type="text" name="birthday" value="<?php echo $arr[0][4] ?>"/></div> </form>
php带入的这种在性别这种单选框时
<?php echo $arr[0][3]?"checked=checked":"" ?>加入判断
<select></select>里面加判断if($arr[0][3]==$v[0]){echo "<option value='{$v[0]}' selected="selected">{$v[1]}</option>";}else{
echo "<option value='{$v[0]}'>{$v[1]}</option>"来实现选中状态。
}
ajax方式
<form action="updatechuli.php" method="post"> <div class="form-group"><label for="ucode">人员编号:</label><select name="ucode" class="form-control" id="ucode"> <?php require_once "../lib/DBDA.class.php"; $db = new DBDA; $sql = "select ucode from users"; $arr = $db->query($sql); foreach($arr as $v){ echo "<option value='{$v[0]}'>{$v[0]}</option>"; } ?> </select></div> <div class="form-group"><label for="uid">用户名:</label><input type="text" class="form-control" name="uid" id="uid"></div> <div class="form-group"><label for="pwd">密码:</label><input type="text" class="form-control" name="pwd" id="pwd"></div> <div class="form-group"><label for="uname">姓名:</label><input type="text" class="form-control" name="uname" id="uname"></div> <div class="btn-group" data-toggle="buttons"> <div>性别:</div> <label class="btn btn-primary"><input type="radio" class="sex" name="sex" id="nan" value="1">男</label> <label class="btn btn-primary"><input type="radio" class="sex" name="sex" id="nv" value="0">女</label> </div> <div class="form-group"><label for="birthday">生日:</label><input type="text" class="form-control" name="birthday" id="birthday"></div> <div ><input type="submit" class="btn btn-success" value="确认修改" ></div> </form>