所以我的表中有4列。前两个是显示名称和用户名。我没有echo
用户名的原因是它是一个md5字符串,更安全。因此,我尝试获取与登录的用户名(the $_COOKIE["USERNAME"]
)关联的显示名称,但$displayuser
返回空查询。另外,我不确定WHERE username = {$c_user}
,{$c_user}
的部分。任何解决方案?
if(isset($_COOKIE['USERNAME']))
{
$c_user = $_COOKIE["USERNAME"];
$con = mysqli_connect("localhost","root","","accounts");
$result = mysqli_query($con,"SELECT 'display name' FROM 'account_info' WHERE username = {$c_user}");
$displayuser = mysqli_query($con,$result);
echo $displayuser;
}
答案 0 :(得分:0)
mysqli_query
的返回值不是字符串。它是mysqli_result
对象或(如果查询失败)FALSE
。
你需要测试它是否是FALSE
(如果它是examine the error(如果你引用的话,我很确定在列名周围使用单引号会引发错误)他们应该用反引号引用)),然后你可以在循环它们之前测试if you have any results和getting each row of data。
答案 1 :(得分:0)
'display name'不能是正确的列名,因为列中不能有空格。
和昆汀是对的。应用于您的示例,您需要这样做:
//see if there is any result
if($result = mysqli_query($con, result))
{
while($fields = mysqli_fetch_field($result))
{
echo $fields->display_name;
}
}