Created
March 3, 2024 19:52
-
-
Save muathendirangu/882b164a42f930ec6303660ede77f9eb to your computer and use it in GitHub Desktop.
code example using prepared statements to prevent from SQL injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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