Quick answer (defensive view): SQL injection (SQLi) is a dangerous web vulnerability that occurs when an application inserts user input into a SQL query without proper handling, letting attackers interfere with the query to read, change or delete data. This article is meant to help developers and administrators prevent it, not to teach attacks. How to prevent it (most important first): (1) use prepared statements / parameterised queries — the most effective measure; (2) use an ORM correctly; (3) validate input with allow-lists; (4) apply least privilege to database accounts; (5) use a WAF and hide detailed error messages; (6) keep frameworks and libraries updated; (7) run regular, authorised security testing. Understanding SQLi helps you build safer applications.
SQL injection is one of the most common and dangerous attack techniques, threatening the integrity and security of data in web applications. This article explains what SQL injection is, why it’s dangerous and how to prevent and control it.
What is SQL injection?
SQL injection is a technique in which attackers insert malicious SQL into an application’s database queries. It works when the application doesn’t handle input correctly, letting attackers exploit the flaw and manipulate the database.
Why is SQL injection dangerous?
It can give attackers access to — and control over — sensitive data in the database. They may steal, delete or modify important data, or even take over the system. Beyond the direct damage, it harms a business’s reputation and customer trust.
Common types of SQL injection
- Error-based: attackers use database error messages to learn about the database structure.
- UNION-based: the UNION operator is abused to combine results and pull data from other tables.
- Blind SQL injection: when no errors are shown, attackers infer information indirectly:
- Time-based: inferring information from the server’s response time.
- Boolean-based: inferring information from true/false differences in responses.
An illustration of the vulnerability
Imagine a login form whose code builds the SQL query by joining the username and password directly into the query string. Specially crafted input can change the query’s logic so that it always returns true — letting someone log in without valid credentials. The fix is to never build queries from raw input, and to pass input as parameters instead:
// Vulnerable: query built by string concatenation
query = "SELECT * FROM users WHERE username = '" + username + "'";
// Safe: parameterised query
stmt = db.prepare("SELECT * FROM users WHERE username = ?");
stmt.execute([username]);Testing for SQL injection vulnerabilities
Only test systems you own or are authorised to test:
- Review input handling: check every place where user input reaches a database query, and confirm parameterised queries are used.
- Use security testing tools: scanners such as Burp Suite, OWASP ZAP or Acunetix help find SQL injection flaws during authorised testing.
Effective prevention
- Prepared statements: separate data from SQL commands so input can’t change the query.
- Input validation: check and validate all input before processing it.
- Stored procedures: when written safely (without dynamic SQL), they reduce direct query building.
- Least privilege: give database accounts only the permissions they need.
- Web application firewall (WAF): detect and block SQL injection attempts.
Tools that help
- Burp Suite: a web application security testing suite.
- OWASP ZAP: a free, open-source web application scanner.
- Acunetix: a web vulnerability scanner.
- SQLMap: an open-source tool for testing SQL injection — use it only with authorisation.
Conclusion
SQL injection is one of the most serious vulnerabilities web applications face. Understanding and applying these defences protects both your data and your business’s reputation. Security isn’t only a technical task — it’s a responsibility to your users.
Contact IT Systems Vietnam
Contact IT Systems at hotline 028.3995.03.59 or contact@itsystems.com.vn. Follow us on Facebook and YouTube.
Unstable office network that needs redesigning?
IT Systems surveys, designs and deploys LAN, Wi-Fi, firewall and VPN for offices and branches, with full documentation.




