0

I need to fix errors of this insert because this don't work in my script. I'm a beginner in WordPress SQL. Thanks

$wpdb->insert('wp_cadastrados', 
    array (
        'ID'            => NULL,
        'nome'          => $_POST['nome_cliente'],
        'email'         => $_POST['email_cliente'],
        'documento'     => $_POST['MeuCPFouRG'],
        'telefone'      => $_POST['MeuTelefone'],
        'curso'         => $_POST['CursoDesejado'],
        'valor_tot'     => number_format($_POST['ValorDoCurso'], 2),
        'quantidade'    => 1,
        'data_cad'      => date('Y-m-d H:i:s')
    ),
    array (
        '%d',
        '%s',
        '%s',
        '%s',
        '%s',
        '%s',
        '%d',
        '%d',
        '%s'
    ) 
);
  • what is the error you getting from this script? try add global $wpdb before $wpdb->insert – Webloper Aug 4 '15 at 10:48
0

Make sure that the value portion of the data parameter's column=>value pairs must be scalar. If you pass an array (or object) as a value to be inserted you will generate a warning similar to mysql_real_escape_string() expects parameter 1 to be string, array given on line 880 in file /var/www/html/wp-includes/wp-db.php".

Rather then above your code is looking correct with :

<?php $wpdb->insert( $table, $data, $format ); ?> 

So finally check that every $_POST are not in array format.

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.