This tutorial will help you to prevent SQL inject in PHP. In this tutorial first, check a basic example of SQL injection process. How can users steal data from your website using SQL injection? This tutorial also includes methods to prevent SQL injection using PHP-MySQLi and PHP-PDO drivers. Simple SQL Injection Example For example, A have a website for Bank. You have provided a web interface to bank customers to view their account number and balance. Your Bank website uses URL like http://example.com/get_account_details.php?account_id=102 to fetch details from the database. For example get_account_details.php have code something like below.
1 2 | $accountId = $_GET['account_id']; $query = "SELECT accountNumber, balance FROM accounts WHERE accountId = $accountId"; |
Customers accountId…