Error executing mysql_query [closed]

-3

When I run mysql_query it gives the following error (even though I can connect to the database without any problems)

Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in C:\xampp\htdocs\LuckTor\index.php on line 57

Warning: mysql_query(): A link to the server could not be established in C:\xampp\htdocs\LuckTor\index.php on line 57

The entire code

        $connect = mysqli_connect("localhost", "user", "senha", "bd") or die('ERRO AO LOGAR!');
        if (!$connect) {
            die('Connect Error (' . mysqli_connect_errno() . ') '
                    . mysqli_connect_error());
        }
        $name = 'Barbie e sua amiga no paraiso';
        $categoria = 'Serie';
        $download = 1569;
        $upload = 1694;
        $magnet = 'magnet:?xt=urn:btih:B250C87526B32E9421AA8FB7599FC11CF3FD1275&dn=Morgan%20-%20A%20Evolu%c3%a7%c3%a3o%202016%20Bluray%20720p%20Dublado%20-%20TPF&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a80%2fannounce&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce';

        $query = mysql_query("INSERT INTO torrents('Nome', 'Categoria', 'DownloadQuantity', 'UploadQuantity', 'Magnet') VALUES ('".$name."', '".$categoria."', '".$download."', '".$upload."', '".$magnet."')");
    
asked by anonymous 24.01.2017 / 14:49

2 answers

3

Try to do this in this connection order: DB_HOST , DB_NOME_USUARIO , DB_SENHA , DB_NOME_BANCO . See:

$conn = new mysqli("localhost", "user", "senha", "bd");

// verifica se encontrou algum erro na conexão
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();            
}  

Also note that $download and $upload are as integers, but in query you are using '".$upload."' and '".$download."' , as strings .

 $query = mysql_query("INSERT INTO torrents('Nome', 'Categoria', 'DownloadQuantity', 'UploadQuantity', 'Magnet') 
VALUES ('".$name."', '".$categoria."', '".$download."', '".$upload."', '".$magnet."')");

Do this:

 $query = mysqli_query($conn, "INSERT INTO torrents('Nome', 'Categoria', 'DownloadQuantity', 'UploadQuantity', 'Magnet') VALUES ('".$name."', '".$categoria."', ".$download.", ".$upload.", '".$magnet."')");

In addition to being is not finding a connection according to the user.

    
24.01.2017 / 14:53
4

You are using mysqli_connect and using mysql_query without i , it does not find the connection and says denied access to the user '' because it does not find the connection.

    
24.01.2017 / 14:54