【问题标题】:radio button php mysql单选按钮 php mysql
【发布时间】:2013-10-07 08:17:33
【问题描述】:

我的单选按钮有问题,我可以编辑和插入,但它没有显示任何内容。我做错了什么?预先感谢您的帮助

单选按钮

<input type="radio" name="visible" value="0"<?php 
                if ($id['visible'] == 0) { echo " checked"; } 
                ?> /> {no}
                &nbsp;
                <input type="radio" name="visible" value="1"<?php 
                if ($id['visible'] == 1) { echo " checked"; } 
                ?> /> {yes}

身份证

enter if(isset($_POST['id'])){
$id=$_POST['id'];
}else{
$id=$_GET['id'];
//echo $id;
} here



@$query  = "SELECT * FROM photographs WHERE id = '$id' ";
    //pokazuje co zostalo zmienione
    echo $query;

    $result = mysqli_query($connection, $query);
    if (!$result) {
        die("zapytanie sie nie powiodlo");
    }
    $row = mysqli_fetch_array($result);

?>

【问题讨论】:

  • 这里到底有什么问题?您无法访问单选按钮的值?
  • 可以添加var_dump($row)的输出吗?
  • 什么是 $id['visible]。哪里来的?
  • mrCode 已经回答,感谢您的时间和回答:)

标签: php mysql radio-button


【解决方案1】:

你的数组是$row,所以$id['visible']应该改为$row['visible']

<input type="radio" name="visible" value="0"<?php 
                if ($row['visible'] == 0) { echo " checked"; } 
                ?> /> {no}
                &nbsp;
<input type="radio" name="visible" value="1"<?php 
                if ($row['visible'] == 1) { echo " checked"; } 
                ?> /> {yes}

附注:您的代码容易受到SQL Injection 的攻击。考虑切换到Prepared Statement

【讨论】:

    猜你喜欢
    • 2013-10-03
    • 2015-06-12
    • 2017-06-23
    • 2011-02-28
    • 2013-06-22
    • 2016-02-08
    • 2015-03-11
    • 2017-04-04
    • 2016-07-11
    相关资源
    最近更新 更多