0

Building a plugin I'm trying to insert something in my DB but isn't works!

My code is like that:

global $wpdb;
$table_name = $wpdb->prefix."mytable"; 
$wpdb->insert(
    $table_name,
    array(
        'name'=>"'".$_POST["name"]."'"
    ),
    array(
        '%s'
    )
);

I have a string in my $_POST["name"] and my database only have 2 columns: id, who is AUTO_INCREMENT and Name.

I don't know if I need do something more than the $wpdb->insert('xxxxxxx') but: Wordpress don't send me any error in PHP or SQL and don't insert anything in my database.

0

I would say the problem is first array. Change it to

array(
    'name' => $_POST['name']
),

You can also use wpdb->show_error() or wpdb->print_error()

To Samuel Elh: wpdb->insert() can escape value itself

  • I'm looking for that error...thanks! I didn't see! Now works well – Marcos May 17 '16 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.