Problem in a user record

0

I turn to you again because the papers were burned ... I do not know what the problem may be. I'm with a registration system, to which I add the validation by google recaptcha. The validation works perfectly, the point is that when verifying that the user is "HUMAN", he then loads the entire sequence of validations that are added in the form. I was detecting that the error occurs to me in the process of recording the data in the users table. To save the data I call a function in PHP that is the following:

function registraUsuario($usuario, $pass_hash, $nombre, $email, $activo, $token, $tipo_usuario, $usuclase){
$ul_list = json_encode($usuclase);

global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO usuarios (usuario, password, nombre, correo, activacion, token, id_tipo, clase, nrologins) VALUES(?,?,?,?,?,?,?,?,?)");
$stmt->bind_param('ssssisisi', $usuario, $pass_hash, $nombre, $email, $activo, $token, $tipo_usuario, $ul_list, $nrologins);

if ($stmt->execute()){
    return $mysqli->insert_id;
} else {
    return 0;
}

}

The error that throws me is that this function returns "0" ... I was seeing all the data that is passed to the function and they are all correct. I want to emphasize that the variable ul_list is an array that happened after the user in the registration process selects several options in a select multiple, raising the codes of the selections made ... I store that array in the CLASS field ... As I told you, I was looking at each of the fields that I send to the function and they are all fine ... I'm afraid the error is in how I keep that data (the array) in the database ... They give me a hand? I thank you very much ...

    
asked by MNibor 03.07.2017 в 18:28
source

2 answers

0

As suggested by @jasilva I share the solution to this problem I had. I have a function made in PHP to which after the validations, the user name, password, password hash, etc. to which I send all the values to register the user in the database. The function, I present them to you:

function registraUsuario($usuario, $pass_hash, $nombre, $email, $activo, $token, $tipo_usuario, $usuclase, $nrologins){
 $ul_list = json_encode($usuclase);
 global $mysqli;
 $stmt = $mysqli->prepare("INSERT INTO usuarios (usuario, password, nombre, correo, activacion, token, id_tipo, clase, nrologins) VALUES(?,?,?,?,?,?,?,?,?)");
 $stmt->bind_param('ssssisisi', $usuario, $pass_hash, $nombre, $email, $activo, $token, $tipo_usuario, $ul_list, $nrologins);

 if ($stmt->execute()){
    return $mysqli->insert_id;
 } else {
    return 0;
 }
 }

Basically it is a function that, as you will see, returns the id number inserted, otherwise it returns zero. Then in the code I analyze the value that this function returns, if it is zero, there is definitely a problem in this function ... otherwise, if the value is nonzero, everything continues forward. The problem I had and as they pointed out to me, was a parameter of the definition of the function that was not happening and that was defined in the insert.

    
answered by 05.07.2017 / 02:52
source
1

Thanks to the contribution of Matías Olivera, he pointed out that one of the parameters he was using in the insert query was not happening ... Of course, very grateful. It is corroborated again that four eyes see better than two ...

    
answered by 03.07.2017 в 19:04