doujiu8145 2015-12-10 08:34
浏览 58
已采纳

检查用户ID已经存在于数据库Mysql中

I want to Check if User id is already exist in database 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";
 }
  • 写回答

4条回答 默认 最新

  • dongwuxie5112 2015-12-10 08:49
    关注

    Just do a count and test if you get any results.
    If you get results you already have the id in the database,
    if you don't get any results the id is not there.

    Also I removed $id = echo "" . $user->id; since we can use $user->id directly in the query.

    One more thing, you should steer away from the mysql_* api since it has been deprecated and move towards mysqli_* or better 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";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理