PHP - Select statement in a foreach loop

Viewed 174

Am trying to run this code:

foreach ($tags as $tag)
{   
    $tag = strtolower($tag);
    $tag = trim($tag);
    echo "<br>" . $tag . " checking<br>";

    $query = "SELECT `tag_id`, `tag_name` FROM TAG where `tag_name` = ?";
    $stmt = mysqli_prepare($connection, $query);
    $stmt->bind_param("s", $tag);

    if ($stmt->execute())
    {
        echo "Success";
    }
    else
    {
        echo "Error";
    }
}

My $tags array has food, school, Birthday, not, There, over, Limit.

The first three elements food, school, Birthday are in my TAG table

The output I get is

food checking
Success
school checking

Then the page crashes with a 500 error and doesn't continue loading. Am really confused on what could be breaking the code here.

0 Answers
Related