Php 如果($currentCount<;=$allowedCount)。。还1个额外的?
出于某种原因,这段代码仍然返回2而不是1Php 如果($currentCount<;=$allowedCount)。。还1个额外的?,php,mysql,if-statement,Php,Mysql,If Statement,出于某种原因,这段代码仍然返回2而不是1 $allowedCount = 1; ( This figure is set inside the database ) $sql_count = mysql_query("SELECT usrid FROM mytable WHERE usrid=".$uid) or die(mysql_error()); $currentCount = mysql_num_rows( $sql_count ); $currentCount = 1; (
$allowedCount = 1; ( This figure is set inside the database )
$sql_count = mysql_query("SELECT usrid FROM mytable WHERE usrid=".$uid) or die(mysql_error());
$currentCount = mysql_num_rows( $sql_count );
$currentCount = 1; ( In this example current count returns a 1 )
if ( $currentCount <= $allowedCount ) {
// do this OK
} else {
// do this Not OK
}
$allowedCount=1;(此图设置在数据库内部)
$sql\u count=mysql\u query(“从mytable中选择usrid,其中usrid=”.$uid)或die(mysql\u error());
$currentCount=mysql\u num\u行($sql\u count);
$currentCount=1;(在本例中,当前计数返回1)
如果($currentCount检查您的数据库,您可能有重复的记录。如果您使用表单插入数据,则可能会在页面刷新时重新插入数据。如果不检查您的数据库是否重复。为什么不使用COUNT(*)
在您的中选择
?根据您从何处获取$uid,这可能是一个潜在的sql注入漏洞。请参阅:@Jared,我会尝试这样做,但我认为我的问题是,如果1@DGM我发布的代码为了简单起见被剥离。我肯定是在从一个不可能被删除的全局数据库中转义并获取usr id改变了。我确实这么认为,但我已经在另一个监视器上打开了phpmyadmin,并确保只有一个条目存在。