Custom registration of users in wordpress

Asked

Viewed 221 times

2

I need to register users in wordpress, and register this user information in another database table

global $wpdb;

if( count($_POST) > 0) {

$userdata = array(
    'user_login'  =>  $_POST['nome'],
    'user_url'    =>  'http://example.com',
    'user_pass'   =>  NULL, // When creating an user, `user_pass` is expected.
    'role' => 'editor'
);

$user_id = wp_insert_user( $userdata );

    $cadastro = $wpdb->insert( 'usuarios',
                                array(
                                        'idusuarios' => $user_id,
                                        'nome' => $_POST['nome'],
                                        'idade' => $_POST['idade'],
                                        'cidade' => $_POST['cidade']
                                )
                            );
    if( $cadastro > 0 ) {
        echo "Cadastrado com sucesso!";
    } else {
        echo"Erro! não foi possível cadastrar";
    }
}

But this error appears:

Warning: mysqli_real_escape_string() expects Parameter 2 to be string, Object Given in C: xampp htdocs rondoloc wp-includes wp-db.php on line 1127

Errors in debug.log :

PHP Notice: Undefined index: name in C: xampp htdocs rondoloc wp-content themes rondoloc page-cadastro.php on line 13

PHP Notice: Undefined index: name in C: xampp htdocs rondoloc wp-content themes rondoloc page-cadastro.php on line 24

PHP Notice: Undefined index: idade in C: xampp htdocs rondoloc wp-content themes rondoloc page-cadastro.php on line 25

PHP Notice: Undefined index: city in C: xampp htdocs rondoloc wp-content themes rondoloc page-cadastro.php on line 26

Wordpress database error column 'name' cannot be null for the INSERT INTO query usuarios (idusuarios, nome, idade, cidade) VALUES (', NULL, NULL, NULL)

done by require('C: xampp htdocs rondoloc wp-blog-header.php'),

require_once('C: xampp htdocs rondoloc wp-includes template-Loader.php'),

include('C: xampp htdocs rondoloc wp-content themes rondoloc page-cadastro.php')

  • Try debugging and attach the log to the question. 1) Open your wp-config.php 2) Add these three lines there: define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); 3) Open the problematic page and then copy and paste the contents of wp-content/debug.log in the question using the formatação. Reference

1 answer

0


Ali no user_pass tá null...and is saying in the comment "When a user is created, user_pass is expected... A string... And Null is returning in object form... Maybe a $_POST['Fieldname'], resolve...

  • thanks, I made the change you indicated and entered in the database, but the first error keeps appearing

  • Next :"mysqli_real_escape_string() expects Parameter 2 to be string, Object Given in C: xampp htdocs rondoloc wp-includes wp-db.php on line 1127" This means : that the function "mysqli...string()" waits for parameter 2 to be a string, given object.... 1127... then the function expects a string and is receiving an object... PQ object? --->>>Wordpress database error Column 'name' cannot be null for query INSERT INTO users (idusuarios, name, age, city) VALUES (', NULL, NULL, NULL) this NULL parameter is being interpreted as object and it needs to be a string.

  • Got it, thanks man, as I put a condition at the beginning of the block, it does not enter the block, and only enters after I pass the strings via POST, and does not present the error, thus making the Insert in the database

  • When you want to validate the answer, if it has been useful, finish it there beside

Browser other questions tagged

You are not signed in. Login or sign up in order to post.