我想在更新页面上显示所选的单选按钮

时间:2017-03-22 06:33:43

标签: php mysql sql radio

我在这里做错了什么?

NSO的Php代码

if(!isset($_POST["nso"])) {
$message = "NSO is required";
}else {
$message = "Did not submit NSO";
}

选择

$sql = mysqli_query($conn, "SELECT * FROM student_prof where studentID = '$id' ") or die("Error: " . mysqli_error($conn));

while($row=mysqli_fetch_array($sql,MYSQLI_ASSOC)){

Html代码

<input type="radio" name="nso" value="Submitted" <?php if(isset($_POST['nso']) && $_POST['nso']=="Submitted") echo 'checked="checked"' ?>> Submitted<br>
<input type="radio" name="nso" value="Not Submitted" <?php if(isset($_POST['nso']) && $_POST['nso']=="Not Submitted") echo 'checked="checked"' ?>>Not Submitted

1 个答案:

答案 0 :(得分:0)

根据您的代码

<input type="radio" name="nso" value="Submitted" <?php if(isset($_POST['nso']) && $_POST['nso']=="Submitted") echo "checked" ?>> Submitted<br>
<input type="radio" name="nso" value="Not Submitted" <?php if(isset($_POST['nso']) && $_POST['nso']=="Not Submitted") echo "checked" ?>>Not Submitted

基于选择查询

<input type="radio" name="nso" value="Submitted" <?php if(isset($row['nso']) && $row['nso']=="Submitted") echo "checked" ?>> Submitted<br>
<input type="radio" name="nso" value="Not Submitted" <?php if(isset($row['nso']) && $row['nso']=="Not Submitted") echo "checked" ?>>Not Submitted