Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
PHP
<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
HTML
<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 database configuration file
							           include('dbConfig.php');

							           //Get all country data
							           $query = $db->query("SELECT * FROM sk_m_states state ORDER BY state ASC");

							           //Count total number of rows
							           $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>
Posted
Updated 5-Nov-17 21:54pm
v4

Hi,

Your database expects an integer value in the field
qual_deg_state_id

but an empty string does not meet that crietria.
Use
intval(qual_deg_state_id)
when you're trying to insert. You will have to give up the implode for this, but it will ensure that the value is an integer.
 
Share this answer
 
Comments
Member 13153537 6-Nov-17 3:52am    
Thanks for your help and support.finally i got the solution.
PHP
//i have just added one line of code  for previous code it is working fine now//
if ($_POST['dynfields']) {
			 //$loopcount=0;
         foreach ( $_POST['dynfields'] as $key=>$fieldArray ) {

             $keys = array_keys($fieldArray);

             $values = array_map("mysql_real_escape_string",$fieldArray);
						 if($values[qual_deg_id] !="")
						 {
 					 	//print_r("values of keys - ".$values[qual_deg_id]);
   					$query = mysql_query("INSERT INTO sk_c_qualification (".implode(',',$keys).",qual_cand_id) VALUES ('".implode('\',\'',$values)."','$cand_id')") or die(mysql_error());
					}

         }
     }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900