我想在下面的函数中从我的数据库中获取数据,但它不起作用,我不明白为什么,有人可以帮忙吗?
$sql1 = "SELECT * FROM users WHERE uname='Honey' AND pass='Honey'";
$count = mysqli_num_rows( mysqli_query($con, $sql1) );
if ($count > 0 ) {
$query = mysqli_query($con, $sql1);
while ($rss = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
function user_names() {
$master = .$rss["uname"].;
$api = "".$master."";
if (empty($api)) return "Missing";
$data = "api=".$api."&mask";
$ch = curl_init();
curl_close($ch);
return $content;
}
}
}
答案 0 :(得分:0)
让我尝试修复您的代码
$sql1 = "SELECT * FROM users WHERE uname='Honey' AND pass='Honey'";
$query = mysqli_query($con, $sql1) ;
$count = mysqli_num_rows($query);
if ($count > 0 ) {
while ($rss = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
user_names($rss);
}
}
function user_names($rss) {
$master = .$rss["uname"].;
$api = "".$master."";
if (empty($api)){
return "Missing";
} else {
$data = "api=".$api."&mask";
$ch = curl_init();
curl_close($ch);
return $content;
}
}
我遗留了一些你不知道的东西,比如$content
,而且我也不知道你在哪里使用$ data,但我认为你有更多的代码,这只是遗留下来的东西。也许你决定返回$data
,但也许不会。
如果你想将一个用户名放在一个函数中,你可以这样做
user_names($rss);
和功能
function user_names($rss){
echo $rss['uname'];
}
答案 1 :(得分:0)
我从您的代码中了解到:
您想要使用提供的用户名和密码检查数据库中的用户是否存在,如果我正确,您可以使用以下代码,否则请相应地更新您的问题。
$sql1 = "SELECT * FROM users WHERE uname='Honey' AND pass='Honey'";
$count = mysqli_num_rows(mysqli_query($con, $sql1));
//If user exists in db with provided credentials
if ($count > 0) {
$query = mysqli_query($con, $sql1);
$rss = mysqli_fetch_array($query, MYSQLI_ASSOC);
$data = "api=" . $rss["uname"] . "&mask";
$ch = curl_init();
curl_close($ch);
return $data;
} else {
return "Missing";
}