i have a form in that i am filling the details of cand 10th,12th,diploma,ug and pg details.i am inserting the data using dynfields array.my problem is if i provide all the details data inserting successfully.but if i fill only single qualification it is giving
Incorrect integer value: '' for column 'qual_deg_state_id' at row 1
error.i tried to print the data using print_r funciton .it showing data what i am passing usinf front-end remaing values are showing empty,why this is happening please help me how to fix this thanks in advance.
What I have tried:
this is my code for inserting the data
<pre> if ($_POST['dynfields']) {
foreach ( $_POST['dynfields'] as $key=>$fieldArray ) {
$boo=$_POST['dynfields'];
print_r($boo);
$keys = array_keys($fieldArray);
$values = array_map("mysql_real_escape_string",$fieldArray);
$query = mysql_query("INSERT INTO sk_c_qualification (".implode(',',$keys).",qual_cand_id) VALUES ('".implode('\',\'',$values)."','$cand_id')") or die(mysql_error());
}
}
//this is my html code
<pre> <div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Board/University<font color="red">*</font></label>
<input name="dynfields['+1+'][qual_deg_university]" value="<?php echo $cand_10_uni ?>"class="form-control" title="Min 4 , Max 150 Only Characters" type="text" placeholder="University/Board" required/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>College<font color="red">*</font></label>
<input name="dynfields['+1+'][qual_deg_college]" value="<?php echo $cand_10_uni ?>" class="form-control" pattern="^[a-zA-Z,\s]{4,150}$" title="Min 4 , Max 150 Only Characters" type="text" placeholder="College" required/>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Year of Passing<font color="red">*</font></label>
<input id="qual_deg_ug_yop" name="dynfields['+1+'][qual_deg_year]" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>State<font color="red">*</font></label>
<?php
include('dbConfig.php');
$query = $db->query("SELECT * FROM sk_m_states state ORDER BY state ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" name="dynfields['+1+'][qual_deg_state_id]" id="qual_deg_ug_state"/>
<option value="">Select State</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['state_id'].'">'.$row['state'].'</option>';
}
}else{
echo '<option value="">State not available</option>';
}
?>
</select>
</div>
</div>