我正在尝试使用php来检查我的数据库以查看是否存在值。我的主要目标是使用此值
$_GET['UDID']
如果它等于数据库中的任何值,它将返回
echo 'FOUND';
我正在使用此代码:
<?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**';
}
}
}
?>
但由于某种原因,它无法正常工作,我相信我一直在寻找一些东西。非常感谢您的帮助。
答案 0 :(得分:4)
试试这个:
$sql = mysqli_query($connect, "SELECT udid FROM data WHERE udid = '" .$udid. "'");
另外,请务必设置&#39; GET&#39; $ udid。应该是这样的:
$udid = $_GET['UDID'];
我们可以使用mysqli_fetch_array()来获取结果行。我还包括错误处理。现在你的代码必须如下所示:
$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 :(得分:0)
我建议你首先使用mysqli_real_escape_string函数转义字符串,然后调用SQL查询。
RowSpan="Auto"