I have a login, that if the user logs in from another cell phone, I register the new playerID (onesignal) on my DB.
The login works fine but does not register the new playerID. And not of the mistake at all, it just does not register.
Follow the code:
<?php
header('Access-Control-Allow-Origin: *');
include 'conn-login.php';
if($_SERVER['REQUEST_METHOD'] == 'GET'){
if($_GET["acao"]=="login"){
$emailL = $_GET['email'];
$senhaL = $_GET['senha'];
$playerID = $_GET['playerID'];
$modelo = $_GET['modelo'];
$sistema = $_GET['sistema'];
$cadastro = 'Facebook';
$face_user_id = $_GET['face_id'];
$datahora = date('Y-m-d h:i:s');
$sql = "SELECT id, nome, img_user, email, senha FROM usuarios WHERE (email =?) LIMIT 1";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('s', $emailL);
$stmt->execute();
$stmt->bind_result($id_user, $nome, $img_user, $email_res, $senha);
$stmt->store_result();
if($stmt->num_rows <> 0){
while ($stmt->fetch()){
// checks if the user actually exists(true/false returned)
if (password_verify($senhaL, $senha)){
$var = Array(
'status' => 'OK',
'id' => $id_user,
'nome' => $nome,
'img_user' => $img_user,
'msg' => 'Logado com sucesso!'
);
$sql2 = "SELECT playerID FROM playersID WHERE (id_usuario =? AND playerID =?)";
$stmt2 = $mysqli->prepare($sql2);
$stmt2->bind_param('is', $id_user, $playerID);
$stmt2->execute();
$stmt2->bind_result($playerID_res);
$stmt2->store_result();
if($stmt2->num_rows <= 0){
while ($stmt2->fetch()){
if($playerID != $playerID_res){
//INSERE O PLAYERID EM OUTRA TABELA
$sql3 = "INSERT INTO playersID (id_usuario, modelo, sistema, playerID, data) VALUES (?, ?, ?, ?, ?)";
$stmt3 = $mysqli->prepare($sql3);
$stmt3->bind_param('issss', $id_user, $modelo, $sistema, $playerID, $datahora);
$stmt3->execute();
}
$stmt3->close();
}
}
} else {
$var = Array(
'status' => 'ERRO',
'msg' => 'Usuário não cadastrado e/ou senha incorreta!'
);
}
$stmt2->close();
}
$stmt->close();
} else {
$var = Array(
'status' => 'ERRO',
'msg' => 'Usuário não cadastrado e/ou senha incorreta!'
);
};
echo json_encode($var);
}
}
?>
What is not registering, is SQL3. Can anyone give me a light of what I'm doing wrong?
Apparently, this is not happening:
while ($stmt2->fetch()){
Thank you!
Note: it is via GET, but later I will change to POST.