Mysql insert only works if a column is 10 charas long

0 Votes
    1233 Views

Got a bizarre issue where $wpdb->insert only works if the meta_type column is 10 charas long.

Here’s the table structure

    CREATE TABLE `wp_djembe563_church_admin_people_meta` (`meta_type` text,
    `people_id` int(11) DEFAULT NULL,`ID` int(11) DEFAULT NULL, `meta_id` 
     int(11) NOT NULL, `meta_date` date NOT NULL ) ENGINE=InnoDB 
    AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

I’m using a function to do the insert – $meta_type=”smallgroup” works, “ministry” doesn’t. The value for meta_type is hard coded in the function call. $meta_type=’1234567890′ works but $meta_type=’123′ doesn’t! So it seems to only work if $meta_type is 10 charas long.

  function church_admin_update_people_meta($ID,$people_id,$meta_type)
  {
    global $wpdb;
     $wpdb->show_errors();
     $id=$wpdb->get_var('SELECT meta_id FROM '.CA_MET_TBL.' WHERE people_id="'.esc_sql($people_id).'" AND meta_type="'.esc_sql($meta_type).'" AND ID="'.esc_sql($ID).'"');
if(empty($id))
{
    $sql='INSERT INTO '.CA_MET_TBL.' (people_id,ID,meta_type,meta_date) VALUES ("'.intval($people_id).'", "'.intval($ID).'", "'.esc_sql($meta_type).'", "'.date('Y-m-d').'" );';
    echo $sql;
    $wpdb->query($sql);
    echo $wpdb->insert_id;
}

}

Copy and paste of echo $sql into phpmyadmin inserts it fine. The other odd thing is that the insert_id is increment even though the query returns no error but is not inserted.
What is going on please?


Please signup or login to answer this question.