drq22639 2017-08-15 01:30
浏览 61
已采纳

检查SQL数据库的值

I am trying to use php to check my database to see if a value exists. My main goal is to use this value

$_GET['UDID']

and if it is equal to any value that is in the database it will return

echo 'FOUND';

I am using this code:

<?php

$servername = "*****";
$username = "*****";
$password = "*****";
$dbname = "*****";
$connect = new mysqli($servername, $username, $password, $dbname);
if ($connect->connect_error) {
    die("CONNECTION FAILED: " . $connect->connect_error);
}

$udid = $_GET['UDID'];
$id = mysqli_real_escape_string($connect, $udid);

$result = mysqli_query($connect, "SELECT udid FROM data WHERE udid = '$id'");

if($result === FALSE) {
   die("ERROR: " . mysqli_error($result));
}
else {
    while ($row = mysqli_fetch_array($result)) { 
          if($row['udid'] == $udid) {
              $results = 'Your device is already registered on our servers.';
              $results2 = 'Please click the install button below.';
              $button = 'Install';
              $buttonlink = 'https://**link here**';
          }
          else {
              $results = 'Your device is not registered on our servers';
              $results2 = 'Please click the request access button below.';
              $button = 'Request Access';
              $buttonlink = 'https://**link here**';
          }
    }
}

?>

But for some reason it is not working, I am sure I am over looking something. your help is greatly appreciated.

  • 写回答

2条回答 默认 最新

  • duanhe6464 2017-08-15 01:32
    关注

    Try this:

    $sql = mysqli_query($connect, "SELECT udid FROM data WHERE udid = '" .$udid. "'");
    

    And also, make sure to set the value from 'GET' to $udid. Should be like this:

    $udid = $_GET['UDID'];
    

    We can use mysqli_fetch_array() instead to get the result row. I also include error handling. Now your code must look like this :

    $udid = $_GET['UDID'];
    $id = mysqli_real_escape_string($connect, $udid);
    
    $result = mysqli_query($connect, "SELECT `udid` FROM `wmaystec_WMT-SS`.`data` = '$id'");
    
    if($result === FALSE) {
       die(mysqli_error("error message for the user")); //error handling
    }
    else {
        while ($row = mysqli_fetch_array($result)) { 
              echo "FOUND :" .$row['thefieldnameofUDIDfromyourDB'];
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看