0

***** problem====can't insert into my table but when i ver_dump it it shows all record needed to be insert====
Here is my sample code.

for ($col = 0; $col <= $highestColumnIndex; $col++) { 
//assigning all data to one variable 
$allcolrowdata =$columnNames = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow($col, $row)->getValue()); 
   //echo $allcolrowdata.'<br>';
   $allcolrowdataexplode=explode(",",$allcolrowdata);
   var_dump( $allcolrowdataexplode).'<br>';
  foreach($allcolrowdataexplode as $key => $inserted){

//echo $inserted;
$query_insert ="INSERT INTO tem_treg2 (title,surname,first_name,middle_name,gender,dob,marital_status,occupation,phone_number,company_name,registration_type,registered_by,tax_id,office_address,office_city,temp_reg,workplace_category,active,monthly_gross,nhf,nhis,nsitf,basic_salary,grade,designation,pension,gratuity) 
VALUES ('','$inserted','','','','','','$textfile_occupation','','$institution','','$UserLogin','','','','','','','','','','','','','','','')
";
//var_dump($query_insert);
//('','$values1','$inserted','','','','','$textfile_occupation','','$institution','','$UserLogin','','','','','','','','','','','','','','','')

}
                }
2
Contributors
3
Replies
26
Views
3 Months
Discussion Span
Last Post by AndrisP
0

Where you define variables $textfile_occupation, $institution, $UserLogin ?
Where you execute $query_insert ?

Edited by AndrisP

0

thanks for your fast repond
here is where i define them

$institution=$_SESSION['Company'];
$UserLogin=$_SESSION['UserLogin'];
$textfile_surname = $_POST['surname'];
$textfile_occupation = $_POST['occupation2'];
$textfile_occupation1 = $_POST['occupation'];
$textfile__monthlygross = $_POST['monthly_gross'];

 mysqli_query($connect, $query_insert);  echo mysqli_error($connect);
0
  1. mysqli_query() should be inside for (line 15)
  2. Use filter_input() to sanitize user input variables
  3. Bind variables after prepare

Edited by AndrisP

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.