When I call $mysqli->real_escape_string($str), I get back a safe string that I can use in a query. It has all special symbols that can lead to SQL Injection Attack escaped.
My question is - what is the correct way to use it in a query later? Do I single quote or double quote this safe string?
For example,
$safe_title = $mysqli->real_escape_string($_POST['safe_title']);
Now do I do this:
$r = $mysqli->query("SELECT * FROM articles WHERE title='$safe_title'");
Or this:
$r = $mysqli->query('SELECT * FROM articles WHERE title="'.$safe_title.'"');
Sometimes I do one, sometimes I do the other, but this one time when I did one of these and typed a bunch of garbage in input, I got an SQL query error somehow. I realized I'm doing it wrong and all my code is probably vulnerable. That's why I'm asking this question here.