Hata bu şekilde

Notice: Undefined variable: db in B:xampphtdocslink-ekle.php on line 7

Fatal error: Uncaught Error: Call to a member function prepare() on null in B:xampphtdocslink-ekle.php:7 Stack trace: #0 {main} thrown in B:xampphtdocslink-ekle.php on line 7
Insert kodları

    if ($_POST){
        $ad = $_POST["ad"];
        $link = $_POST["link"];
        echo "Proje Ad : ". $ad . "<br> Proje Link :" . $link;
        $query = $db->prepare("INSERT INTO link SET
        link_ad = ?,
        link_link = ?");
        $insert = $query->execute(array(
         $ad, $link
        ));
        if ( $insert ){
         $last_id = $db->lastInsertId();
         print "insert işlemi başarılı!";
        }
    }else{
        
    }