因此,我尝试使用此脚本检查成员“订阅”是否在我的网站上处于活动状态。
1表示是0表示否
现在,我只是试图显示查询的结果,但它没有显示在屏幕上。
如果有人能帮上忙,我将不胜感激。
<?php
require_once 'config.php';
// If session variable is not set it will redirect to login page
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
header("location: login.php");
exit;
}
$query = "SELECT Subscription FROM users WHERE username="$_SESSION['username']"";
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
$result = mysqli_query($link, $query);
?>
<!DOCTYPE html>
<html>
<head>Test</head>
<body>
<h1> Subscription= <?php echo htmlspecialchars($result); ?></h1>
</body>
</html>
发布于 2018-08-21 04:54:27
一点小小的仁慈:
<?php
require_once 'config.php';
// If session variable is not set it will redirect to login page
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
header("location: login.php");
exit;
}
// initialize variable
$yes_no = 0;
// note string syntax; curly bracing is helpful with bracket and object notation;
// also, single quote as username is likely not a non-string type in the database
$query = "SELECT Subscription FROM users WHERE username='{$_SESSION['username']}'";
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
$result = mysqli_query($link, $query);
if ($result && $result->num_rows) {
$yes_no = $result->num_rows;
}
?>
<!DOCTYPE html>
<html>
<head>Test</head>
<body>
<h1> Subscription= <?php echo $yes_no; ?></h1>
</body>
</html>
正如AbraCadaver所指出的,修复字符串变量$query应该允许它运行。初始化一个变量将有助于消除错误日志,并且测试DB操作的结果是SOP,您应该尽快开始使用它。
https://stackoverflow.com/questions/51938163
复制相似问题