使用复选框插入到数据库


insert to database with checkbox

我正在尝试找到一种使用复选框将值上传到SQL的方法,但没有运气

这是我的代码:

/////////////////////////// FOR RXTRA ////////////////////////////////////////////////////////////
$sql = "SELECT ext_id,ext_price,ext_name,ext_description FROM tbl_extra ORDER by ext_id ASC";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
$number = mysql_num_rows($result);
$i = 0;
while ($number > $i) {
  $ID = mysql_result($result,$i,"ext_id");
  $NA= mysql_result($result,$i,"ext_name");
  $PR= mysql_result($result,$i,"ext_price");
  $DES= mysql_result($result,$i,"ext_description");
  //this part chack if the value is "0" and show with "tooltip" the value'/
  if ( $PR == 0 ) {
    print '<a href="#" class="tooltip2">'.$NA.'<span>' .' free '.'</span></a>!';
  } else {
    print '<a href="#" class="tooltip2">'. $NA .'<span>' .' add '.'  '. $PR .' $ '. '</span></a>!';
}
print "<input style='width: 30px; height: 15px;' type='checkbox'  name='extra[]' value='$NA'></td>'n";
//this java calculate the value add to extra ant outpot the total extra that pass to sql table
print "<input type='hidden' name='item_name'/>";
print "<input type='hidden' name='amount'/>";

print "<input style='width: 30px; height: 15px;' type='checkbox' onClick='ReadForm (this.form, false);' value='+$PR'></td>'n";
$i++;
}
?>
</div></div>
<?
} else {
}
?>
<!----->
<div class="item_add_cart">
<span class="title">total extra $</span>
<div class="content">
<?
print "<input style='color:#000;font-size:13px;' size='7' name='tot' type='text'/>";
?>
</div></div>
<!----->

我的问题是我有两个表,一个是总价,一个是名称,我尝试用一个复选框插入所有值,但它不起作用

如果我创建 2 个复选框并单击它们,则值上传正常但我只需要一个复选框,将值从 $NA 发送到表 ext_name 并将总价从 name='tot' 发送到表 ext_price

请注意,上面的代码不起作用,@Majid Fouladpour 建议使用以下代码。

/////////////////////////// FOR RXTRA ////////////////////////////////////////////////////////////
$sql = "SELECT ext_id,ext_price,ext_name,ext_description FROM tbl_extra ORDER by ext_id ASC";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
$number = mysql_num_rows($result);
$i = 0;
while ($number > > $i) {
$ID = mysql_result($result,$i,"ext_id");
$NA= mysql_result($result,$i,"ext_name");
$PR= mysql_result($result,$i,"ext_price");
$DES= mysql_result($result,$i,"ext_description");
//this part chack if the value is "0" and show with "tooltip" the value'/
if ( $PR == 0 ) {
    print ''.$NA.'' <a href="#" class="tooltip2">'.$NA.'<span>' .' free '.'!';
.'</span></a>!';
} else {
    print ''. <a href="#" class="tooltip2">'. $NA .'' '<span>' .' add '.'  '. $PR .' $ '. '!';
</span></a>!';
}
print "'n";<input style='width: 30px; height: 15px;' type='checkbox'  name='extra[]' value='$NA'></td>'n";
//this java calculate the value add to extra ant outpot the total extra that pass to sql table
print "";
<input type='hidden' name='item_name'/>";
print "";<input type='hidden' name='amount'/>";

print "'n";
<input style='width: 30px; height: 15px;' type='checkbox' onClick='ReadForm (this.form, false);' value='+$PR'></td>'n";
$i++;
}
?>


total >
</div></div>
<?
} else {
}
?>
<!----->
<div class="item_add_cart">
<span class="title">total extra $</span>
<div class="content";
>
<?
print "<input style='color:#000;font-size:13px;' size='7' name='tot' type='text'/>";
?>

>
</div></div>
<!----->

(我已经在社区维基上做了这个答案,所以代表不会去找我)