I am trying to prevent SQL injection in a Select statement.
When this is just about values (as for the Like part here) I use "bind_param
" as in the example below which works as intended.
However, I am having issues with the variable column name since I cannot use "bind_param" for this.
Can someone tell me how I can prevent SQL injection for the variable column name ($language
) as well (the current code is working)?
My PHP:
$language = "some language";
$location = "some location";
// ...
$stmt = $conn->prepare("SELECT tID, " . $language . " FROM Main WHERE location LIKE ? ORDER BY sortOrder, " . $language);
$stmt->bind_param("s", $location);
$stmt->execute();
// ...