I'm trying to generate an users creation page and I make a validation to determine if the user already exists, for that I use the next code:
here i insert the user and his password to the table USERS
mysqli_stmt_bind_param($guardar_usuario, 'ss', $usuario,$encriptar);
mysqli_stmt_execute($guardar_usuario);
here i reuse the variable $user to recover the new id user created
$consulta = "SELECT id_usuario FROM usuario WHERE usuario = '$usuario' ORDER BY fecha_registro DESC LIMIT 1";
$ultimo_registro = mysqli_prepare($connect,$consulta);
mysqli_stmt_execute($ultimo_registro);
mysqli_stmt_bind_result($ultimo_registro, $id_usuario_creado);
mysqli_stmt_fetch($ultimo_registro);
I insert the extra data to a table named PERSONAS
$guardar_persona = mysqli_prepare($connect, "INSERT INTO persona (id_usuario, nombre, email) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($guardar_persona, 'iss', $ultimo_registro, $nombre_usuario, $email_usuario);
mysqli_stmt_execute($guardar_persona);
My problem is that the second query, the data insert to the table PERSONAS doesn't work, but if I remove the first query which makes the insert to the table USERS, this query works perfectly, so I dont know if is there a rule to make this work?
Sorry if its a quite newbie question, just started to work this way to try to prevent as much as possible data inyection.