You haven't shown the whole command but I'm going to guess you need to drop the use of ' around $afields[0]. So more like array('ein' -> $afields[0]) instead.
Earnie
On Mon, Jul 23, 2012 at 4:07 PM, Anthony tony@tony-mac.com wrote:
I am trying to insert data into a newly created table with $result = db_insert('cc_npo_storage') ->fields(array( 'ein' => '$afields[0]',
table is defined
- CREATE TABLE `cc_npo_storage` (
- `ein` varchar(10) NOT NULL,
The data I am inserting into field ein is ( '$afields[0]') Array[0] => 010759876
(I used the php command explode to take apart a delimited input string thus the array).
My problem is that I am getting the following message: PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'ein' at row 1: INSERT INTO {cc_npo_storage} (ein, name, city, state, country, tforeign, flagged, nid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => $afields[0] [:db_insert_placeholder_1] => $afields[1] [:db_insert_placeholder_2] => $afields[2] [:db_insert_placeholder_3] => $afields[3] [:db_insert_placeholder_4] => $afields[4] [:db_insert_placeholder_5] => $afields[5] [:db_insert_placeholder_6] => $afields[6] [:db_insert_placeholder_7] => $afields[7] ) in insertdata() (line 125 of \sites\all\modules\custom\input\input.module).
I have googled to no avail.
Thanks for any help Tony
--
Anthony Stefan Maciejowski
-- [ Drupal support list | http://lists.drupal.org/ ]