What is the common error message that occurs when using the mysql_query function in PHP, and how can it be resolved?

The common error message that occurs when using the mysql_query function in PHP is "mysql_query(): Access denied for user 'user'@'localhost' (using password: YES)". This error typically indicates that the username or password provided in the connection settings is incorrect. To resolve this issue, ensure that the correct username and password are used in the connection settings.

<?php
$servername = "localhost";
$username = "correct_username";
$password = "correct_password";
$dbname = "database_name";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Perform query
$sql = "SELECT * FROM table_name";
$result = mysqli_query($conn, $sql);

// Rest of the code
?>