Are there any security considerations to keep in mind when using buttons to send SQL queries in PHP?

When using buttons to send SQL queries in PHP, it is important to sanitize user input to prevent SQL injection attacks. This can be done by using prepared statements and parameterized queries to ensure that user input is treated as data rather than executable code.

// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Sanitize user input
$query = "SELECT * FROM users WHERE username = :username";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':username', $_POST['username']);
$stmt->execute();

// Fetch data
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Display results
foreach ($results as $row) {
    echo $row['username'] . "<br>";
}