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 ofwp-content/debug.log
in the question using theformatação
. Reference– Florida