Achot: Fatal error: Call to a member function

Beitrag lesen

Guten Morgen,

ich komme mal wieder nicht weiter.

function bestandNachEingabe($mysqli, $Eingabe=false){
        
    if ($Eingabe) {

        $sql = "SELECT SUM(bestand) AS `summeBestand`, titel 
                  FROM artikel WHERE MATCH(`titel`) AGAINST(? IN BOOLEAN MODE) ";
        $res->bind_param("s", $Eingabe);
            
    }
        
    else {

        $sql = "SELECT SUM(bestand) AS `summeBestand` FROM artikel";

    }
        
    $res = $mysqli->prepare($sql);
    $res->execute();
    $res->bind_result($summeBestand);
    $res->fetch();
    $res->close();  

    return $summeBestand; 
}

Wenn ich diese Funktion aufrufe, erhalte ich folgende Fehlermeldungen

Notice: Undefined variable: res in line 8
Fatal error: Call to a member function bind_param() on a non-object

Was mache ich falsch?