What is the potential issue with the mysql_query() function in the provided PHP script?

The potential issue with the mysql_query() function in the provided PHP script is that it is deprecated in newer versions of PHP and is no longer supported. It is recommended to use mysqli_query() or PDO to interact with a MySQL database in PHP for better security and performance. To solve this issue, you should update the code to use mysqli_query() or PDO for database queries.

// Fix for using mysqli_query() instead of mysql_query()

// Establishing a connection to the MySQL database using mysqli
$mysqli = new mysqli("localhost", "username", "password", "database_name");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Query to select data from a table using mysqli_query()
$result = $mysqli->query("SELECT * FROM table_name");

if ($result) {
    // Fetch data from the result set
    while ($row = $result->fetch_assoc()) {
        echo "ID: " . $row["id"] . " - Name: " . $row["name"] . "<br>";
    }
} else {
    echo "Error: " . $mysqli->error;
}

// Close connection
$mysqli->close();