Skip to content

Instantly share code, notes, and snippets.

@muathendirangu
Created March 3, 2024 19:52
Show Gist options
  • Save muathendirangu/882b164a42f930ec6303660ede77f9eb to your computer and use it in GitHub Desktop.
Save muathendirangu/882b164a42f930ec6303660ede77f9eb to your computer and use it in GitHub Desktop.
code example using prepared statements to prevent from SQL injection
<?php
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); // Basic sanitization
$sql = "SELECT * FROM users WHERE name = :name";
$stmt = $db->prepare($sql);
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment