Reputation: 1560
I have an List which field is dynamic getting by import xlxs. I have generate an array list. Insert work while only xlxs file has 1 record But does not work while getting multiple rows.
When has more than 1 array it says:
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 2
then sql code
My array lists are given below :
Array(
[0] => Array
(
[name] => Md. XXXX
[email] => [email protected]
[mobile_no] => 1751017812
[password] => $2y$10$vgmdsjT64aXHQcPA6vh8LuWfdWWA/NCtC8NLYTl8yyQ/wtXdcSNHy
[user_type_id] => 1
[designation] => Sr. Software Engineer
[market_code] => mirpurA203
[product_code] => Seclo201
[territori_code] => T352
[region_code] => Mirpur334
[division_code] => Dhaka31
)
[1] => Array
(
[name] => Md. XX
[email] => [email protected]
[mobile_no] => 1761017812
[password] => $2y$10$52CtpkGrKfriInOmnz.guOrIvnCJyxgYRbfEkDl6nFkPD2UYcvhiO
[user_type_id] => 2
[designation] => Sr. Software Engineer
[territori_code] => T352
[region_code] => Mirpur334
[division_code] => Dhaka31
)
)
I tried with eloquent and DB insert also but it's work while having an only single record.
Upvotes: 3
Views: 2334
Reputation: 33186
When inserting multiple items at once, all rows should have the same items. This is because MySQL expects this. An insert query specifies the columns to insert once and expects all the data that follows to match those columns.
INSERT INTO `table` (`col_1`, `col_2`, `col_3`) VALUES (`val_11`, `val_12`, `val_13`), (`val_21`, `val_22`, `val_23`)
Your second object is missing market_code
and product_code
. Either add these to each record or insert the records separately.
Upvotes: 6