I have a select statement to get some data from my mysql server. I wanna find some keywords for e.g. c in a list like this a,b,c,d,e,f that is stored under the tags column on the mysql server. My question is why this code won't work?
if(isset($_GET['TAG'])){
$type="tags";
$content = '%'.$_GET['TAG'].'%';
}
$sql = "SELECT * FROM `images` WHERE ? LIKE ? ORDER BY `timerec` DESC;";
$s=$dbh->prepare($sql);
$s->execute(array($type, $content));
$data=$s->fetchAll();
echo json_encode($data);
exit;
The variable dbh is the pdo that I will not post here cause it is 100% working and contain sensible information. The $_GET['TAG'] can contain a keyword. Please do not correct any security risks in this code if there are any, I just want to know what is wrong with the following code.