0.0/10
verdict: needs_serious_help
"SQL injection nightmare fueled by laziness"
lang: PHP·5 lines
//your_submission
SqlInjectionVortex.php
<?php
$id = $_GET['id'];
$query = "SELECT * FROM users WHERE id = " . $id;
$result = $db->query($query);
?>//detailed_analysis
!
SQL Injection
You're directly injecting user input into the SQL query. Congratulations, you've just opened the doors to a world of SQL injection attacks. Get a security book, or better yet, a career change.
!
Lack of Input Sanitization
Where's the input validation? Did you just assume users would play nice? Newsflash: they won't. Sanitize, validate, and for the love of security, use prepared statements.
?
Potential Database Exposure
Your code is a leak waiting to happen. With no error handling and a direct query execution, you're risking exposing your database credentials. Add some error handling, and consider using an ORM or a query builder.
//suggested_fix
SqlInjectionVortex_fixed.php
+$id = (int) $_GET['id'];
+$query = "SELECT * FROM users WHERE id = ?";
+$stmt = $db->prepare($query);
+$stmt->bind_param("i", $id);
+$stmt->execute();
+$result = $stmt->get_result();