开发者

Access denied when trying to access my database [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

Here's my code:

<html>
    <h开发者_JS百科ead>
    </head>

    <body>
        <?php 
            $user = mysql_real_escape_string($_GET["u"]);
            $pass = mysql_real_escape_string($_GET["p"]);

            $query = "SELECT * FROM usario WHERE username = '$user' AND password = '$pass'";

            mysql_connect(localhost, "root", "");
            @mysql_select_db("multas") or die( "Unable to select database");

            $result=mysql_query($query);
            if(mysql_numrows($result) > 0){
                echo 'si';
            }   
         ?>
    </body>
</html>

And here's the error I get when I try to run it

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\useraccess.php on line 7

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\useraccess.php on line 7

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\useraccess.php on line 8

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\useraccess.php on line 8

Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\useraccess.php on line 16


You need to make your database connection before you call

mysql_real_escape_string

if you don't want to do that, use

mysql_escape_string

instead, since it doesn't care about the connection


Move mysql_connect(localhost, "root", ""); above $user = ...


You need to put single quotes around 'localhost':

mysql_connect('localhost', 'root', '');

Also, a blank root password? Really?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜