作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Possible Duplicate:
Submit an HTML form with empty checkboxes
我正在尝试向数据库提交一些数据。我正在尝试将表单中复选框的值提交到数据库,如下所示:
<input type='checkbox' name='continue' <?php if ($_POST[continue] == TRUE) echo "value='y' checked='checked'"; else echo "value='n'"; ?> />
当我在选中复选框时提交数据时,该值将为“y”。但是当选中该复选框时,没有数据发送到数据库。
请指教。
最佳答案
解决方案 1:(更好的方法)
<input type="checkbox" name="continue"<?php echo (isset($_POST['continue']) ? ' checked="checked"' : ''); ?> />
在您的数据库(?)文件中:
$continue = isset($_POST['continue']) ? 'y' : 'n';
.
解决方案 2:(不推荐)
<input type="hidden" name="continue" value="<?php echo isset($_POST['continue']) ? 'y' : 'n'; ?>" />
<input type="checkbox" name="continue_x"<?php echo (isset($_POST['continue']) ? ' checked="checked"' : ''); ?> onclick="document.getElementsByName('continue')[0].value=this.checked?'y':'n';" />
关于PHP 复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11072476/
我是一名优秀的程序员,十分优秀!