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条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?