mysqli_fetch_assoc()期望参数1为mysqli_result,[duplicatione]中给出布尔值

时间:2017-11-12 21:46:48

标签: php html html5

// If logged in, access mysql
$con =  mysqli_connect(DB_HOST, DB_USER, DB_PASS) or die(mysqli_error);

$user = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM users WHERE username='" . $_SESSION['username'] . "'"));
echo '<ul>';

我的表名为users,我的用户名列为username

图片HERE

2 个答案:

答案 0 :(得分:0)

查询不正确删除会话中的两个点 像这样查询

xor eax,eax

答案 1 :(得分:0)

首先,您不要定义DB_NAME(数据库名称)

$con =  mysqli_connect(DB_HOST, DB_USER, DB_PASS,DB_NAME) or die(mysqli_error);


$userName = $_SESSION['username']; 
$stmt = mysqli_query($con,"SELECT * FROM users WHERE username ='$userName' ");
while( $user = mysqli_fetch_assoc($stmt) ){
  // if correct will pass to here
}

如果错误仍然存​​在 从数据库中获取任何名称并使用参数

进行切换