Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用复选框插入到数据库_Php_Mysql_Sql - Fatal编程技术网

Php 使用复选框插入到数据库

Php 使用复选框插入到数据库,php,mysql,sql,Php,Mysql,Sql,我试图找到一种方法,使用复选框将值上载到SQL,但运气不好 这是我的代码: /////////////////////////// FOR RXTRA //////////////////////////////////////////////////////////// $sql = "SELECT ext_id,ext_price,ext_name,ext_description FROM tbl_extra ORDER by ext_id ASC"; $result = mysql_que

我试图找到一种方法,使用复选框将值上载到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>
<!----->
RXTRA的
//////////////////////////////////////////////////////////////
$sql=“按ext\U id ASC从tbl\U额外订单中选择ext\U id、ext\U价格、ext\U名称、ext\U说明”;
$result=mysql\u query($sql)或trigger\u error(mysql\u error(),E\u USER\u error);
$number=mysql\u num\u行($result);
$i=0;
而($number>$i){
$ID=mysql_result($result,$i,“ext_ID”);
$NA=mysql_result($result,$i,“ext_name”);
$PR=mysql_结果($result,$i,“外部价格”);
$DES=mysql_result($result,$i,“ext_description”);
//此部分检查值是否为“0”,并用“工具提示”显示该值\/
如果($PR==0){
打印“!”;
}否则{
打印“!”;
}
打印“\n”;
//这个java计算add to extra ant的值,输出传递给sql表的总额外值
打印“”;
打印“”;
打印“\n”;
$i++;
}
?>
全部额外费用$

请注意,上面的代码不起作用,@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>
<!----->
RXTRA的
//////////////////////////////////////////////////////////////
$sql=“按ext\U id ASC从tbl\U额外订单中选择ext\U id、ext\U价格、ext\U名称、ext\U说明”;
$result=mysql\u query($sql)或trigger\u error(mysql\u error(),E\u USER\u error);
$number=mysql\u num\u行($result);
$i=0;
而($number>>$i){
$ID=mysql_result($result,$i,“ext_ID”);
$NA=mysql_result($result,$i,“ext_name”);
$PR=mysql_结果($result,$i,“外部价格”);
$DES=mysql_result($result,$i,“ext_description”);
//此部分检查值是否为“0”,并用“工具提示”显示该值\/
如果($PR==0){
打印“.$NA”。!”;
}否则{
打印“”。!”;
}
打印“\n”;\n”;
//这个java计算add to extra ant的值,输出传递给sql表的总额外值
打印“”;
";
打印“;”;
打印“\n”;
\n”;
$i++;
}
?>
总数>
全部额外费用$

@所有人,请大家,如果有人张贴代码,不要修复问题中的代码,除了布局。在回答中修复它。@all,否则OP所问的问题将无法识别。此代码有太多问题。(1) 最后一个
}else{}
将导致语法错误(或者您可能有一个open
if
块,该块在此处发布的代码片段之前开始);(2)
项目名称
金额
的隐藏输入应为数组:
项目名称[]
金额[]
;(3) 您没有为这些隐藏输入指定任何值。(4) 这里需要包含javascript
ReadForm
函数,我们看不到它的作用。(5) 此代码段是创建表单的部分,您没有显示负责将值插入db的后端提交处理程序。@Majid为什么不在回答中指出这些,OP应该如何从错误中吸取教训,如果他/她一开始甚至看不出它有什么问题,因为有人删掉了错误。尤其是当投诉
无效时
@John,我没有想到你使用的技巧(在社区维基上给出答案),我也有同样的担心;)