Many references like W3schools and Wikipedia state "If the original statement template is not derived from external input, SQL injection cannot occur".
What does this mean exactly? I've tried to search more on the subject but most references leave it at exactly that.
To be more specific, I am talking about: If the original statement template is not derived from external input
As, I've researched as to why it cannot occur.
Does this mean, as long as you don't directly put the user input into the query, like:
SELECT * FROM pubs WHERE " . $_POST['extra'] . " LIKE '%Yes%'
as opposed to:
SELECT * FROM pubs WHERE ? LIKE ?
Also, is it okay to pass a column name as a parameter like i've done above. For instance say I have
$extra = $_POST['extra'];
$yes = "%Yes%";
and then I prepare:
$stmt = $mysqli->prepare(SELECT * FROM pubs WHERE ? LIKE ?);
and then bind:
$stmt->bind_param("ss", $extra, $yes);
Is this safe an correct?