gpt4 book ai didi

php - 检查 SQL 数据库的值

转载 作者:搜寻专家 更新时间:2023-10-30 20:08:02 25 4
gpt4 key购买 nike

我正在尝试使用 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**';
}
}
}

?>

但由于某种原因它不起作用,我确定我正在寻找一些东西。非常感谢您的帮助。

最佳答案

试试这个:

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

此外,请确保将值从“GET”设置为 $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'];
}
}

关于php - 检查 SQL 数据库的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45685292/

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