What is the main issue with the PHP script for the photo gallery?
The main issue with the PHP script for the photo gallery is that it is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection attacks. To solve this issue, you should use prepared statements with parameterized queries to prevent SQL injection.
// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=gallery', 'username', 'password');
// Prepare a SQL statement with a parameterized query
$stmt = $pdo->prepare('SELECT * FROM photos WHERE id = :id');
// Bind the parameter
$stmt->bindParam(':id', $_GET['id']);
// Execute the query
$stmt->execute();
// Fetch the results
$photo = $stmt->fetch();