[英]Broken If statment in SQL Query
好吧,我向自己摇了摇头,因为我知道这很明显,但我只是不明白。 查询应返回1个结果,并带有匹配的用户名和密码,然后-我只需要检查行中的“状态”列/字段设置为“非活动”还是“挂起”-如果是,则将值设置为$ count并设置一个$ _SESSION个味精值。
就目前而言,状态检查不起作用-是因为我在比较column.field名称吗? $ result ['状态']?
我的查询如下:
$sql="SELECT * FROM $tbl_name WHERE User_Name='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// Verified E-Mail address check
if ($result['Status']=="Inactive") {$count=5;$_SESSION['msg']=="Not Verified";};
您需要先从结果中获取数据行,然后才能比较值。
像这样:
$result = mysql_query($sql);
$data = mysql_fetch_array($result);
if ($data['Status'] == 'Inactive') {
...
}
话虽如此,有充分的理由不使用mysql_ *函数。
有关更多详细信息, 请参见此问题: 为什么我不应该在PHP中使用mysql_ *函数?
您应该使用mysql_fetch_array
或mysql_fetch_assoc
从查询中获取数据数组。
$sql="SELECT * FROM $tbl_name WHERE User_Name='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// Verified E-Mail address check
$row = mysql_fetch_array($result);
if ($row['Status']=="Inactive") {$count=5;$_SESSION['msg']=="Not Verified";};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.