Вот имеется такой код:
$result = $mysqli->query("SELECT * FROM users WHERE social_id='$social_id'", MYSQLI_USE_RESULT);
$num = $result->num_rows;
if($num > 0){
setcookie("token",$toki);
setcookie("uid",$social_id);
setcookie("hash",$hash);
header("location:/");
}else{
$aquery = $mysqli->query("INSERT INTO users (social_id,hash,regdate,token,name,surname) VALUES ('$social_id','$hash','$time','$toki','$social_name','$social_surname')", MYSQLI_USE_RESULT) or die(mysqli_error($mysqli));
if($aquery){
echo "okay";
}else{
echo "oops";
}
}