Well, table and column names cannot be replaced by parameters in PDO. As a requirement, mentioning static column name
is not possible here. So, I use santize
. Is it enough to prevent sql injection like bind param
method. What can be best method ?
$id = filter_var($_POST['id'], FILTER_SANITIZE_STRING);
$text = filter_var($_POST['text'], FILTER_SANITIZE_STRING);
$column_name = filter_var($_POST['column_name'], FILTER_SANITIZE_STRING);
$result = $con->query("UPDATE menu SET $column_name='$text' WHERE mid=$id") OR die($con->error);