I've been reading this and when reaching the part of addslashes mitigation I came across this:
$id = addslashes( $_GET['id'] );
$query = 'SELECT username FROM users WHERE id = ' . $id;
Saying it's vulnerable to SQL Injection but not this:
$uname = addslashes( $_GET['id'] );
$query = 'SELECT username FROM users WHERE id = "' . $uname . '"';
How is the first vulnerable and why?
This comes when I'm looking at some old code that uses this syntax:
$query = "SELECT * FROM users WHERE user='$user' AND password='$password'";
The variables are addslashed before using them, but still I've been told this is vulnerable. I know the right practices call for PDO this days, but it just caught me cold when I couldn't explain to myself how this would be vulnerable.
Can somebody give me some example in where it could be bypassed addslashes? Besides GBK charset
EDIT: After reading the reply post, I perhaps need to clarify: The idea is getting to know what values could trigger the problems, and why, not how to avoid it as I'm already using PDO in the testbed, but want to learn from old mistakes as well and in-depth.