This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result
                                
                                    (32个答案)
                                
                        
                                6年前关闭。
            
                    
所以我有这段代码:

$query = "SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER($name)";
$result = mysql_query($query);
list($count) = mysql_fetch_row($result);
if($count >= 1) {
echo 'Username already exists; }


出于某种原因,当我在wamp服务器上对其进行测试时,我回来了:“警告:mysql_fetch_row()期望参数1为资源,布尔值在...中给出”,但是它完成了工作!用户已注册。我知道您必须先执行查询,然后获取行,但是我做到了!那么问题出在:/

最佳答案

如果$ name是文字,则可能需要在SQL中将其引用:

$query = "SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('$name')";


您还应该确保它不包含任何未转义的引号(请参阅有关bobby-tables的先前评论...)

关于php - mysql_fetch_row()错误,但为什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17480105/

10-13 00:58