[英]how to store data into database from dynamically generated second drop down from first in php?
Here i am trying to store the data from second drop down list which is generated dynamically from first drop down list using javascript.It will store the value of first drop down named category but it will not store value of second dropdown named Sb_category into my db table,There is an code i have try...please check it and give me right way!!!!! 在这里,我试图存储第二个下拉列表中的数据,该列表是使用javascript从第一个下拉列表动态生成的。它将存储第一个下拉命名类别的值,但它不会将名为Sb_category的第二个下拉列表的值存储到我的数据库中表,有一个我试过的代码...请检查一下,给我正确的方法!!!!!
Form i have used: 我用过的表格:
<div class="form-group" id="style_container_div">
<label>Choose Category: </label>
<select size="1" id="Category" class="form-control" title="" type="select" name="Category" value="-Select Your Category-">
<optgroup>
<option value="">-Select Your Category-</option>
<option value="Charging">Charging</option>
<option value="Consent">Consent</option>
<option value="Content">Content</option>
<option value="Feature">Feature</option>
<option value="Navigation_flow">Navigation flow</option>
<option value="Service_Consuption">Service Consuption</option>
<option value="Service_Provisioning">Service Provisioning</option>
</optgroup>
</select>
<div class="clear"></div>
<div id="error-message-style"></div>
</div>
<div id="Charging" class="style-sub-1" style="display: none;" name="stylesub1" onchange="ChangeDropdowns(this.value)">
<label>Which Sub-Category? </label>
<select id="Charging" name="Charging" class="form-control">
<optgroup>
<option value="">-Choose A Sub-Category-</option>
<option value="Charging">Charging</option>
</optgroup>
</select>
</div>
<div id="Consent" class="style-sub-1" style="display: none;" name="stylesub1" onchange="ChangeDropdowns(this.value)">
<label>Which Sub-Category? </label>
<select id="Consent" name="Consent" class="form-control">
<optgroup>
<option value="">-Choose A Sub-Category-</option>
<option value="Accuracy">Accuracy</option>
<option value="Double_Confirmation">Double Confirmation</option>
<option value="Single_Confirmation">Single Confirmation</option>
</optgroup>
</select>
</div>
PHP file i have used in form action:\\ 我在表单操作中使用的PHP文件:\\
if(isset($_POST['submit']))
{
}else{
header('Location:AddTestCase.php');
}
$conn = mysqli_connect('localhost', 'root', '','tmtool');
if($conn -> connect_errno )
{
die('coudn\'t connect to the database' . mysqli_connect_error());
}
if(! get_magic_quotes_gpc() )
{
$Category = addslashes(filter_input(INPUT_POST, 'Category'));
$Sub_category = addslashes(filter_input(INPUT_POST, 'stylesub1'));
}
else
{
$Category = (filter_input(INPUT_POST, 'Category'));
$Sub_category = (filter_input(INPUT_POST, 'stylesub1'));
}
if(($sql = $conn->prepare("INSERT INTO tmtool.testcase_master (`Category`, `Sub_category`) VALUES (?, ?)"))== FALSE)
{
echo "false";
}
$sql->bind_param('ss',$Category , $Sub_category);
if($sql->execute())
{
echo "Entered data successfully\n";
mysqli_close($conn);
}
else {
die('Could not enter data: ' . mysqli_error($conn));
}
Name of your second drop-down is Charging
not stylesub1
. 第二个下拉列表的名称是Charging
not stylesub1
。 please check that. 请检查一下。
<div id="Charging" class="style-sub-1" style="display: none;" name="stylesub1" onchange="ChangeDropdowns(this.value)">
<label>Which Sub-Category? </label>
<select id="Charging" name="Charging" class="form-control">
<optgroup>
<option value="">-Choose A Sub-Category-</option>
<option value="Charging">Charging</option>
</optgroup>
</select>
</div>
So while accepting in PHP
use Charging
keyword in the place of stylesub1
因此,在PHP
接受时,在stylesub1
的位置使用Charging
关键字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.