gpt4 book ai didi

javascript - 仅当选中关联的复选框时才插入输入文本数据 MySql

转载 作者:行者123 更新时间:2023-11-29 21:47:08 25 4
gpt4 key购买 nike

这是我的 HTMl 代码,实际上我想插入输入文本数据,前提是仅选中该复选框,并且有 50 多个带有独特数据的输入字段可以像这样的 HTML 插入

<div class="row">
<form action="" method="post" name="country_form" class="form" role="form">
<div class="form-group">

<div class="col-lg-3 col-xs-12 bg-info">
<div class="squaredOne pull-left">
<input type="checkbox" value="" id="Asian" name="check[0]" />
<label for="Asian"></label>
</div>
<span class="pull-left">Asian</span><span class="clearfix"></span>
<input class="bg-alert" type="number" id="bales" name="Asian[0]" min="0" placeholder="Asian Bales">
</div>

<div class="col-lg-3 col-xs-12 bg-info">
<div class="squaredOne pull-left">
<input type="checkbox" value="" id="BabyGrow" name="check[1]" />
<label for="BabyGrow"></label>
</div>
<span class="pull-left">Baby Grow</span><span class="clearfix"></span>
<input class="bg-alert" type="number" id="bales" name="BabyGrow[1]" min="0" placeholder="Baby Grow Bales">
</div>

<div class="col-lg-3 col-xs-12 bg-info">
<div class="squaredOne pull-left">
<input type="checkbox" value="" id="Boys_Pants" name="check[2]" />
<label for="Boys_Pants"></label>
</div>
<span class="pull-left">Boys Pants</span><span class="clearfix"></span>
<input class="bg-alert" type="number" id="bales" name="Boys_Pants[2]" min="0" placeholder="Boys Pant Bales">
</div>

<div class="col-lg-3 col-xs-12 bg-info">
<div class="squaredOne pull-left">
<input type="checkbox" value="" id="Boys_Colour_Shirts" name="check[3]" />
<label for="Boys_Colour_Shirts"></label>
</div>
<span class="pull-left">Boys Colour Shirts</span><span class="clearfix"></span>
<input class="bg-alert" type="number" id="bales" name="Boys_Colour_Shirts[3]" min="0" placeholder="Boys Colour Shirt Bales">
</div>

<div class="form-group">
<input type="button" value="Next" class="btn-block btn btn-lg btn-info"/>
</div>

</form>
<div>
</div>

此外,在我的数据库中,所有输入字段都位于单独的列中像这样CT_ID |亚洲 |宝贝成长 |婴儿裤 |婴儿彩色衬衫等(60 多栏)

在复选框字段 Check[0] 中和在输入文本 Asian[0] 数组中相同,正确吗?我怎样才能做到这一点

我要插入或更新的 PHP 代码的想法是:

for ($j = 0; $j < count($_POST['check']); $j++) {
if (!empty($_POST['check'][$j])) { /* CHECK IF CHECKBOX IS SELECTED */
$q = "INSERT INTO container (Asian, BabyGrow) VALUES ('$Asian','$BabyGrow')";
$q = mysql_query($q);
}
}

但我不确定,而且很难为 50 多个具有独特输入字段的 div 框编写 html

最佳答案

将一个新的品味页面粘贴到下面的代码,并了解您做错了多少件事。1)您没有使用提交按钮来提交和发布值。2)您没有正确命名表单中的输入。 3)php代码中的逻辑。4)尚未检查页面是否发布

<div class="row">
<form action="" method="post" name="country_form" class="form" role="form">
<div class="form-group">

<div class="col-lg-3 col-xs-12 bg-info">
<div class="squaredOne pull-left">
<input type="checkbox" value="Asian" id="Asian" name="check[0]" />
<label for="Asian"></label>
</div>
<span class="pull-left">Asian</span><span class="clearfix"></span>
<input class="bg-alert" type="number" id="bales" name="Asian" min="0" placeholder="Asian Bales">
</div>

<div class="col-lg-3 col-xs-12 bg-info">
<div class="squaredOne pull-left">
<input type="checkbox" value="BabyGrow" id="BabyGrow" name="check[1]" />
<label for="BabyGrow"></label>
</div>
<span class="pull-left">Baby Grow</span><span class="clearfix"></span>
<input class="bg-alert" type="number" id="bales" name="BabyGrow" min="0" placeholder="Baby Grow Bales">
</div>

<div class="col-lg-3 col-xs-12 bg-info">
<div class="squaredOne pull-left">
<input type="checkbox" value="Boys_Pants" id="Boys_Pants" name="check[2]" />
<label for="Boys_Pants"></label>
</div>
<span class="pull-left">Boys Pants</span><span class="clearfix"></span>
<input class="bg-alert" type="number" id="bales" name="Boys_Pants" min="0" placeholder="Boys Pant Bales">
</div>

<div class="col-lg-3 col-xs-12 bg-info">
<div class="squaredOne pull-left">
<input type="checkbox" value="Boys_Colour_Shirts" id="Boys_Colour_Shirts" name="check[3]" />
<label for="Boys_Colour_Shirts"></label>
</div>
<span class="pull-left">Boys Colour Shirts</span><span class="clearfix"></span>
<input class="bg-alert" type="number" id="bales" name="Boys_Colour_Shirts" min="0" placeholder="Boys Colour Shirt Bales">
</div>

<div class="form-group">
<input type="submit" value="Next" name="submit" class="btn-block btn btn-lg btn-info"/>
</div>

</form>
<div>
</div>
<?php
if(isset($_REQUEST['submit'])){
echo "<pre>";
$query = " INSERT INTO container (";
$cols=$vals="";
foreach($_REQUEST['check'] as $chkbx){
if(isset($_REQUEST[$chkbx]) && $_REQUEST[$chkbx]!=""){
$cols.=$chkbx.", ";
$vals.="'".$_REQUEST[$chkbx]."', ";

}
}
$vals=rtrim($vals,', ');
$cols=rtrim($cols,', ');
echo $query."<br/>".$cols." ) Values (<br/>".$vals.")";
}

?>

关于javascript - 仅当选中关联的复选框时才插入输入文本数据 MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34019437/

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