【问题标题】:Radiobuttons through php && mysql, but gives the wrong value通过 php 和 mysql 的单选按钮,但给出了错误的值
【发布时间】:2011-08-30 02:01:14
【问题描述】:
<form>
<?php
$stylesheet = array("style_default.css" => "Default", "style_red.css" => "Red");
foreach($stylesheet as $key => $value)
{
    echo '<input type="radio" name="style" value="'.$key.'" checked="';
    if($css == $key){echo 'yes';} else{echo 'no';}
    echo '" /> '.$value.'<br />';
}

?>

    <input type="submit" name="style_change" value="Spara inställningar" />
</form>

这是我用来创建单选按钮的代码。在我的数据库中,我有一个保存单选按钮值的表。我在页面上得到了路径正确的视觉证明,并且我还检查了 $css 在 echo 的帮助下给出了正确的值。 我的值是“style_default.css”,但我只选择了红色按钮。有谁知道这一切出了什么问题?

【问题讨论】:

  • 它来自更高层的一段代码,在 mysql 代码中。正如我所说:我已经检查过了,所以它给出了正确的值。

标签: php mysql html forms radio-button


【解决方案1】:
$css = "style_default.css"; //assumption
$stylesheet = array("style_default.css" => "Default", "style_red.css" => "Red");
foreach($stylesheet as $key => $value){
    echo '<input type="radio" name="style" value="'.$key.'" '; echo ($css == $key)? 'checked>' : '">'; echo $value.'<br/>';
}

【讨论】:

  • 恐怕现在它们都是空白的。
【解决方案2】:

checked 属性仅接受 checked 和一个空字符串作为其值。例如:checked="checked"checked="" 是正确的。

【讨论】:

    猜你喜欢
    • 2019-04-27
    • 2013-12-14
    • 1970-01-01
    • 2014-11-14
    • 2017-05-29
    • 2013-10-07
    • 2014-05-14
    • 1970-01-01
    • 2015-01-29
    相关资源
    最近更新 更多