I have an array of tag names which I passed via POST Method and I these tag names has its corresponding tag_id in the database. All I want is to search the id while iterating the array of tag names and I want the result of each query to be stored in an empty array. I think I just misunderstood something or what.
$tags_array = ['shoes','gadgets','fashion','food'];
$tags_array_id = [];
$tags_sql = '';
foreach ($tags_array as &$tag) {
$sql = "SELECT tag_id FROM `tbltag` WHERE tag_name = ".$tag." group by tag_name";
$query = mysqli_query($conn, $sql);
$result = mysqli_fetch_row($query);
$tags_array_id[] = $result[0];
};
Please help guys, suggestions highly appreciated.
inand loop through the results.$tagisn't quoted. if$tags_arraycomes from user input you're vulnerable to sql injection$tags_arraystatic on the question material because its fetched from db. Many to mention. But thanks by the way (Y)