mysql访问被用户''@ localhost'拒绝访问数据库''

Yu *_*Son -3 php mysql

这是我在config.php中的当前代码:

mysql_connect("localhost","roof") or die(mysql_error());
mysql_select_db("tarclibrary") or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)

这是我在register.php中的当前代码:

require('config.php');

if(isset($_POST["submit"])){

//Perform the verification of the nation
$email1 =$_POST['email1'];
$email2 =$_POST['email2'];
$pass1 =$_POST['pass1'];
$pass2 =$_POST['pass2'];

if($email1 == $email2){
    if($pass1 == $pass2){
        //All good.carry on

        $fname = mysql_real_escape_string($_POST['fname']);
        $lname = mysql_real_escape_string($_POST['lname']);
        $uname = mysql_real_escape_string($_POST['uname']);
        $pass1 = mysql_real_escape_string($pass1);
        $pass2 = mysql_real_escape_string($pass2);
        $email1 = mysql_real_escape_string($email1); 
        $email2 = mysql_real_escape_string($email2);

        $pass1= md5($pass1);

        $sql = mysql_query("SELECT * FROM 'users' WHERE 'uname' = '$uname'");
        if(mysql_num_rows($sql) > 0){
            echo "Sorry, that user already exits";
            exit();
        }

        mysql_select_db('library') or die(mysql_error());

        mysql_query("INSERT INTO users (id, fname, lname, uname, pass, email) VALUES (NULL, '$fname', '$lname', '$uname'. '$pass1', '$email1')") or die (mysql_error());


    }else{
        echo "sorry,your passwords do not match.<br/>";
        exit();
    }
}else{
    echo "sorry your email's do not match<br/><br/>";
}
}else{

$form = <<<EOT

<h1><center>Register</center></h1>
<br>
<form action="register.php" method="post">
<table class="t1" align="center" width="600" height="400">
<tr>
   <th scope="row">First name</th>
   <td><input type="text" name="fname" required type="text"/></td>
</tr>
<tr>
   <th scope="row">Last name</th>
   <td><input type="text" name="lname" required type="text"/></td>
</tr>
<tr>
   <th scope="row">Username</th>
   <td><input type="text" name="uname" required type="text"/></td>
</tr>
<tr>
   <th scope="row">Password</th>
   <td><input type="password" name="pass1" required type="text" /></td>
</tr>
<tr>
   <th scope="row">Confirm Password</th>
   <td><input type="password" name="pass2" required type="text"/></td>
</tr>
  <tr>
   <th scope="row">Email</th>
   <td><input type="text" name="email1" required type="text"/></td>
</tr>
<tr>
   <th scope="row">Confirm Email</th>
   <td><input type="text" name="email2" required type="text"/></td>
  </tr>
</table>
<input id="register" type="submit" value="Register" name="submit"/>
</form>

EOT;

echo $form;

}
Run Code Online (Sandbox Code Playgroud)

当我提交我的注册表时,输出是:

用户''@ localhost'访问被拒绝到数据库'library'

有人帮忙,为什么会这样?

Mit*_*tul 5

尝试连接以下内容

mysql_connect("localhost","root", '') or die(mysql_error())
Run Code Online (Sandbox Code Playgroud)

MYSQL已弃用所以请使用mysqli