WordPress Insert – Error – Unknown column

I am updating a wordpress insert query that previously worked perfectly.
I am adding a single form text input and adding a single varchar field to the database.

When I add the textfield to the form and I try to insert this into the database I get the error:

Read More
WordPress database error: [Unknown column 'data_created_by' in 'field list']

I have been looking for a solution for the last 2 hours and I read about hidden whitespace, database not setup correctly but this error occurs no matter what I name the database field and no matter what I name the form input.

Form input

<input type="text" id="data-created-by" name="data-created-by" class="form-control" value="" />

MySQL Insert

if($wpdb->insert(
'cram_management',
array(
    'user_id'           => get_current_user_id(),
    'from'              => $from_date,
    'to'                => $to_date,
    'other_comments'    => $_POST["other-comments"],
    'outputs_comments'  => $_POST["outputs-comments"],
    'outcomes_comments' => $_POST["outcomes-comments"],
'data_comments'     => $_POST["data-comments"],
'data_created_by'   => $_POST["data-created-by"]
),
array(
    '%d',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s',
    '%s'
    )
)){ echo "success;"}

I get success when I omit the line (and the corresponding %s)

'data_created_by'   => $_POST["data-created-by"]

I checked in phpmyadmin and there are no spaces in the field name.
I can add content to this field using phpmyadmin.
I removed all whitespace in the HTML and php also, to no avail.

Database

CREATE TABLE IF NOT EXISTS `cram_management` (
`management_id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`from` date NOT NULL,
`to` date NOT NULL,
`other_comments` text NOT NULL,
`outputs_comments` text NOT NULL,
`outcomes_comments` text NOT NULL,
`data_created_by` varchar(80) default NULL,
`data_comments` text NOT NULL,
PRIMARY KEY  (`management_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;

If anyone can tell me why I am getting this error I would be grateful.

Mark

Related posts

Leave a Reply