gpt4 book ai didi

php - 检查用户id是否已经存在于Mysql数据库中

转载 作者:行者123 更新时间:2023-11-29 21:44:49 25 4
gpt4 key购买 nike

我想检查用户 ID 是否已存在于数据库中 print false

$token  = "token";
$data = json_decode(get_html("https://graph.facebook.com/$user->id&access_token=$token"))->data;

$id = echo "".$user->id;
$result = mysql_query("SELECT * FROM token_all WHERE id = $id");
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$checkid = row[id];
}
if ($id == $checkid){
echo "true";
}else{
echo "false";
}

最佳答案

只需进行计数并测试是否得到任何结果。
如果你得到结果,你已经在数据库中拥有了 id,
如果您没有得到任何结果,则说明 id 不存在。

我还删除了 $id = echo ""。 $user->id; 因为我们可以直接在查询中使用 $user->id

还有一件事,您应该远离 mysql_* api,因为 it has been deprecated并走向mysqli_*或更好的PDO

$token  = "token";
$data = json_decode(get_html("https://graph.facebook.com/$user->id&access_token=$token"))->data;

$result = mysql_query("SELECT * FROM token_all WHERE id = " . $user->id);
$count = mysql_num_rows($result); // edited here

if ($count > 0){
echo "ID already exists";
}else{
echo "ID doesn't exist";
}

关于php - 检查用户id是否已经存在于Mysql数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34197054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com