我在页面上有几个带有单选按钮的表单。我的目标是通过单击单选按钮立即更新数据库。到目前为止,这是我汇总的内容,但我不确定从这里去哪里。
<? include 'dbconnect.inc.php';?>
<script type="text/javascript">function do_submit(){document.forms['decision'].submit();}</script>
<? $result = $mysqli->query("SELECT * FROM items");
while( $row = $result->fetch_assoc() ){ ?>
<form name='decision' method='post' action='action.php'>
<label>Keep:</label><input type='radio' name='dec' value='keep' onchange='do_submit()' <? if($row['Dec1']=='keep'){echo "checked='checked'";} ?> >
<label>Donate:</label><input type='radio' name='dec' value='donate' onchange='do_submit()' <? if($row['Dec1']=='donate'){echo "checked='checked'";} ?> >
<label>Sell:</label><input type='radio' name='dec' value='sell' onchange='do_submit()' <? if($row['Dec1']=='sell'){echo "checked='checked'";} ?> >
<label>Trash:</label><input type='radio' name='dec' value='trash' onchange='do_submit()' <? if($row['Dec1']=='trash'){echo "checked='checked'";} ?> >
<label>Give To:</label><input type='text' name='dec' size='15' onchange='do_submit()' <? if($row['Dec1']!='keep' || $row['Dec1']!='donate' || $row['Dec1']!='sell' || $row['Dec1']!='trash'){echo $row['Dec1'];} ?> >
<input type='hidden' name='Id' value='<? echo $row['Id']; ?>' />
</form>
<? } ?>
动作.php
<? $mysqli->query("UPDATE items SET Dec1 = '{$_POST['dec']}' WHERE Id = '{$_POST['$Id']}'") or die(mysqli_error($mysqli)); ?>
我在附近吗?有人可以帮我解决这个问题吗?