dongya767979565 2013-11-30 17:57
浏览 109
已采纳

MySQL查询不返回值

I am trying to get values from MySQL database where the value of the Username column is the same as the parameter being passed in. The parameter being passed in is "Griffin".

function logIntoDb($username)
{
$users = mysqli_query($GLOBALS['con'], "SELECT Id, Username FROM Users WHERE $username=Username");
while($row = mysqli_fetch_array($users))
{
echo "\"Match: " . $row['Id'] . "=" . $row['Username'] . "\"";
echo " - " . ($username==$row['Username'] ? "true" : "false");
echo "<br/>";
}
}

The above keeps returning an empty result, which causes my while loop to throw this warning.

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/a654/public_html/Top/Bottom/log.php on line 16

Here is the Users table:

Id|CreatedOn|Username|Info|Status|Rank|Total|

1|0000-00-00 00:00:00|Peter|123|Good|High|111.11

2|0000-00-00 00:00:00|Griffin|123|Bad|Low|000.00

Is there something that I am not seeing that prevents the Griffin row from being returned?

  • 写回答

3条回答 默认 最新

  • doutan8601 2013-11-30 17:59
    关注

    Your query should be "SELECT Id, Username FROM Users WHERE '$username'=Username"

    You need the single quotes since it's a string and not a number.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?