【发布时间】:2014-10-10 23:45:18
【问题描述】:
我正在使用 html 表单来编辑 sql db,因此我希望表单显示数据库中当前的值。我正在使用 while 循环来显示所有 sql 行。我简单的单选按钮允许用户在“列表”(在 sql 中显示为“0”)或“最近的交易”(在 sql 中显示为“1”)之间进行选择。
单选按钮未从已检查或未检查的 sqlas 中预填充值
<form name="edit listing" action="edit_list.php" method="post" id="edit_form" >
<ul>
<?php while ($data=mysqli_fetch_assoc($result)):
$transaction = $data['transaction'];
$chkvalue='checked="checked"'; ?>
<li>
<fieldset>
<legend>Designation <h6>Required</h6></legend>
<input name="transaction" type="radio" tabindex="11" value="0" <?php if ($transaction == '0') echo $chkvalue; ?> />
<label for="listings">Listings</label>
<input name="transaction" type="radio" tabindex="12" value="1" <?php if ($transaction == '1') echo $chkvalue; ?> />
<label for="recent_transactions">Recent Transactions</label>
</fieldset>
<input type="submit" formaction="edit_list.php" value="Submit Changes" />
</form>
</li>
<?php endwhile;mysqli_close($con);?>
</ul>
简短的 php 插入工作,一点点。我的源代码看起来像这样:
<input name="transaction" type="radio" tabindex="11" value="0" />
<label for="listings">Listings</label>
<input name="transaction" type="radio" tabindex="12" value="1" checked="checked" />
<label for="recent_transactions">Recent Transactions</label>
但单选按钮没有预填充。
我整天都在研究这个问题,这里有任何可能出现问题的建议都会非常有帮助
【问题讨论】:
-
你必须只写
checked而不是check="checked"! -
这也没有填写
-
做一个
var_dump($transaction);告诉我们你得到了什么,这样我们可以更好地帮助你 -
按原样处理您的 HTML 我在默认情况下选中选中的单选按钮没有任何问题。
-
@Crackertastic,我现在看到它必须与如何使用