Welcome Guest, Not a member yet? Register   Sign In
Entering varchar datatype field data into the database table
#1

[eluser]Unknown[/eluser]
Hello All,

I am new to codeigniter.I am trying to insert a varchar datatype value into the table. So its showing unknown column or feild name. Its not inserting the value into the table. I am using default codeigniter insert function like this
$this->db->insert('mytable', $data);
But it not enclosing the field of datatype varchar while inserting into the table.

Below is the table structure and code what I am using to insert.

CREATE TABLE IF NOT EXISTS `products` (
`products_id` varchar(128) NOT NULL,
`quantity` int(10) unsigned default NULL,
`merchant_id` int(10) unsigned NOT NULL,
`modified_date` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`products_id`,`merchant_id`),
KEY `FK_products_1` (`merchant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

$insertData = array( ‘products_id’=> $productId,
‘quantity’ => $qty,
‘merchant_id’ => 1
);
$this->db->insert(‘products’, $insertData);


Thanks in advance.
#2

[eluser]srisa[/eluser]
Can you post little bit more code? Also, make sure that the column names match with those in the database.
#3

[eluser]Unknown[/eluser]
Hi, Below is the code
$insertData = array( 'products_id'=> $productId,
'quantity' => $qty,
'merchant_id' => 1
);
$this->db->insert('products', $insertData);

In products table products_id is VARCHAR datatype, quantity and merchant_id are integer.
#4

[eluser]therealmaloy[/eluser]
veer

just check your column names from your table. the field names may not be the same as to what you've used here in your CI code.

If you still can't get it to work, please post your table structure along with the necessary codes, so that we can properly check on it. Smile




Theme © iAndrew 2016 - Forum software by © MyBB