samedi 21 avril 2018

if row exists within foreach doesn't work

I am trying to echo message in case of row exist or not. But it doesn't work. What is error in following code. Maybe foreach clause caused problem. Please help

if(isset($_POST["section_name"])){
foreach ($_POST["section_name"] AS $key => $item) {               
$query =$con->prepare("SELECT class_id, section_name FROM section WHERE class_id= ':class_id' && section_name ':section_name')");
$query->bindParam(':section_name',$_POST["section_name"][$key]);
$query->bindParam(':class_id', $_POST["class_id"]);
$query->execute();
$count = $query->fetchColumn();
    if ($count === 1)
    {
        echo "Section found";
    }
    else 
    {
        echo "Section is not found";
    }
}
}

Aucun commentaire:

Enregistrer un commentaire