What is the potential issue with storing MySQL queries in a separate PHP page and returning the result to the calling page?

Storing MySQL queries in a separate PHP page can lead to security vulnerabilities such as SQL injection if the queries are not properly sanitized. To solve this issue, you should use prepared statements with parameterized queries to prevent SQL injection attacks. By using prepared statements, you can separate the query logic from the data, ensuring that user input is treated as data rather than executable SQL code.

// Example of using prepared statements with parameterized queries to prevent SQL injection

// Establish a database connection
$mysqli = new mysqli("localhost", "username", "password", "database");

// Prepare a statement with a parameterized query
$stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
$stmt->bind_param("s", $username);

// Set the parameter values and execute the query
$username = "admin";
$stmt->execute();

// Bind the result variables
$stmt->bind_result($id, $username, $email);

// Fetch the results
while ($stmt->fetch()) {
    echo "ID: $id, Username: $username, Email: $email <br>";
}

// Close the statement and the connection
$stmt->close();
$mysqli->close();