While developing a PHP Application I thought about this situation: A user submits some kind of text in a form, on the serverside the text is escaped and inserted into the database. The question is: Is a SQL Injection in the last Query (which uses the value from DB) possible?
Example (I don't think that I have to explain my database class):
$db->query("INSERT INTO accounts SET test='".$db->escape($_POST["sometext"])."'");
Ok, so far I know nothing can happen, in theory i could have done this with an prepared Statement too, makes no difference.
Sometimes later the value of the column test is needed for use in another script and the value needs to get inserted somewhere else.
So the column is selected, and later inserted.
$db->query("SELECT test FROM accounts WHERE ... LIMIT 1");
$row = $db->fetchRow();
$db->query("INSERT INTO secoundtable SET test='".$row["test"]."'");
So as you can see, the value of the database is used in the last Query. Do I have to escape here?