我们使用下面的代码来避免在我们的数据库中插入重复的输入,但在某些情况下它不起作用
$device_id = $_REQUEST['device_id'];
$fcm_id = $_REQUEST['fcm_id'];
$model_number = $_REQUEST['model_number'];
$os_version = $_REQUEST['os_version'];
$app_version = $_REQUEST['app_version'];
$created = round(microtime(true) * 1000);
if(isset($device_id)){
$exist = mysqli_query($con, "SELECT * FROM `user` WHERE `device_id`='$device_id'");
if(mysqli_num_rows($exist)>0){
mysqli_query($con, "UPDATE `user` SET `fcm_id`='$fcm_id', `topics`=0 WHERE `device_id`='$device_id'");
}
else{
mysqli_query($con, "INSERT INTO `user` (`device_id`, `fcm_id`, `model_number`, `os_version`, `created`) VALUES ('".$device_id."', '".$fcm_id."', '".$model_number."', '".$os_version."', '".$created."')");
}
繁华开满天机
慕的地10843