What are the potential pitfalls of using outdated PHP functions like mysql_query in code?

Using outdated PHP functions like `mysql_query` can pose security risks as they are vulnerable to SQL injection attacks. It is recommended to use modern functions like `mysqli_query` or `PDO` which provide better security features and support for prepared statements. By updating your code to use these functions, you can mitigate the risks associated with outdated functions.

// Connect to MySQL using mysqli
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

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

// Use mysqli_query to execute SQL queries
$result = mysqli_query($conn, "SELECT * FROM table");

// Fetch data using mysqli_fetch_assoc
while ($row = mysqli_fetch_assoc($result)) {
    echo "Name: " . $row["name"] . "<br>";
}

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