gpt4 book ai didi

PHP 复选框值

转载 作者:行者123 更新时间:2023-11-29 06:07:01 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com