I am trying to send information to my database after making two queries, the first if the user already exists and the second if the email already exists subsequently made the "upload of information" to my database with my sentence prepared This is my code:
$loadtodatabase = $conn_reg->prepare("INSERT INTO usus (id, paterno ,materno ,nombre ,usuario ,pass ,email ,lvl ,telefono ,fecha ,code ,active ,profileimg)VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ");
$loadtodatabase->bind_param("sssssssssssss", $id, $paterno, $materno, $nombre, $usuario, $pass, $email, $lvl, $telefono, $joining_date, $code, $active, $profileimg );
$checkuser = $conn_reg->prepare ("SELECT 'id', 'nombre', 'paterno', 'materno', 'usuario', 'pass', 'email', 'lvl', 'telefono', 'fecha', 'code', 'active', 'profileimg' FROM 'usus' WHERE 'usuario' = ?");
$checkuser->bind_param("s", $nombre);
$checkuser->execute();
$checkuser->bind_result($id_d,$nombre_d,$paterno_d,$materno_d,$usuario_d,$pass_d,$email_d,$lvl_d,$telefono_d,$fecha_d,$code_d,$active_d,$profileimg_d);
if ($checkuser->fetch()) {
if($usuario = $usuario_d) {
echo "ya fue utilizado el nombre";
}else {
$checkmail = $conn_reg->prepare ("SELECT 'id', 'nombre', 'paterno', 'materno', 'usuario', 'pass', 'email', 'lvl', 'telefono', 'fecha', 'code', 'active', 'profileimg' FROM 'usus' WHERE 'email' = ?");
$checkmail->bind_param("s", $email);
$checkmail->execute();
$checkmail->bind_result($id_d,$nombre_d,$paterno_d,$materno_d,$usuario_d,$pass_d,$email_d,$lvl_d,$telefono_d,$fecha_d,$code_d,$active_d,$profileimg_d);
if ($checkmail->fetch()) {
if($email = $email_d) {
echo "ya fue utilizado el correo";
}else {
if( $loadtodatabase->execute()){
echo "datos guardados";
}else {echo "error ";
}
}
}
}
}
if I use already registered users, if you give me the errors, depending if it is a user already busy or an email already occupied, but at the end of everything does not save the information in the database.
In case you do not understand the code very much, I explain it quickly:
Variables are loaded from $ _POST (this is not seen in the code, do not consider it useful)
The prepared statement is made to write the information but it is not executed.
queries if the variable $ user exists in the database (if it exists, it shows the error if it does not exist, it continues with an "else")
queries if the variable $ email exists in the database (if it exists, it shows the error if it does not exist, it continues with an "else")
------- Here is the problem ---------- if $ loadtodatabase manages to run it shows "saved data" (otherwise it shows error).
How can I solve that fault? the variables are well written and if I do "echo" to see if they have saved data shows them.