What are potential security risks associated with passing parameters in SQL scripts through links in PHP?

Passing parameters in SQL scripts through links in PHP can expose your application to SQL injection attacks. To prevent this, you should always sanitize and validate user input before using it in SQL queries. One way to do this is by using prepared statements with parameterized queries, which separate the SQL query logic from the user input.

// Get parameter from URL
$id = $_GET['id'];

// Create a prepared statement
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");

// Bind the parameter
$stmt->bindParam(':id', $id, PDO::PARAM_INT);

// Execute the query
$stmt->execute();

// Fetch the results
$results = $stmt->fetchAll();