开发者

Radiobuttons through php && mysql, but gives the wrong value

开发者 https://www.devze.com 2023-03-07 04:53 出处:网络
<form> <?php $stylesheet = array(\"style_default.css\" => \"Default\", \"style_red.css\" => \"Red\");
<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>开发者_如何转开发

Here is the code I use to create radio-buttons. On my database I have a table that saves the value of the radio-buttons. I got visual proof on the page that the the path is correct and I have also checked so $css gives the right value with the help of echo. The value I have is "style_default.css", but I only get the button for red selected. Anyone who knows where all this went wrong?


$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/>';
}


The checked attribute accepts only checked and an empty string as its value. For example: checked="checked" or checked="" are correct.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号