What potential pitfalls should be considered when creating a photo gallery using PHP and MySQL?

One potential pitfall to consider when creating a photo gallery using PHP and MySQL is the risk of SQL injection attacks if user input is not properly sanitized before being used in database queries. To prevent this, always use prepared statements or parameterized queries to ensure that user input is treated as data and not executable code.

// Example of using prepared statements to prevent SQL injection

// Assuming $conn is the database connection

// Prepare a statement
$stmt = $conn->prepare("SELECT * FROM photos WHERE id = ?");
$stmt->bind_param("i", $photoId);

// Set the parameter and execute the query
$photoId = $_GET['id'];
$stmt->execute();

// Fetch results
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    // Display photo information
}

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