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!!!!!
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:\
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
";
mysqli_close($conn);
}
else {
die('Could not enter data: ' . mysqli_error($conn));
}
Name of your second drop-down is 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