Adding new pages dynamically using php and mysql

I have been trying to add new pages dynamically from the dashboard using php and mysql.

I am using below code to add new pages.

But I am getting the error as 'id is not defined' in newly added page which contains $filecontent value.

//add.php

<?php include("db.php"); ?>

<?php
    session_start();
    if(isset($_POST['Submit'])) {
        $filename = $_POST['pagename'];
        $pagetitle = $_POST['title'];
        $pagedescription = $_POST['description'];
        $sql = "INSERT INTO addfile (pagename , title, description) VALUES ('$filename' , '$pagetitle' , '$pagedescription')";

        $ConnectingDB->exec($sql);
        $id=$ConnectingDB->lastInsertId();

        $_SESSION['id'] = $id;
        include "page.php";
        
    }
    ?>
<form class="forms-sample" action="add.php" method="post">
<div class="form-group">
  <label for="">Page Name</label>
  <input type="text" class="form-control" name="pagename" placeholder="pagename">
</div>
<div class="form-group">
  <label for="">Title</label>
  <input type="text" class="form-control" name="title" placeholder="title">
</div>
<div class="form-group">
  <label for="">Description</label>
<input type="text" class="form-control" name="description" placeholder="description">
</div>
                  
<button type="submit" name="Submit" class="btn btn-primary">Publish</button>
//page.php

<?php 
session_start();
$_GET['id'] = $_SESSION['id'];
ini_set('display_errors','0');
error_reporting(0);

$pagename = '../'.$filename. '.php' ;

$myfile = fopen( $pagename, "w");
$filecontent = ' <?php 
session_start();
include "include/db.php";
$id = $_GET["id"];
$sql=$ConnectingDB->prepare("select * from addfile where id=$id");
$sql->execute(array());
$file=$sql->fetch(PDO::FETCH_ASSOC);
<div class="content">
        <div class="row">
        <div class="pageana">
        <div class="col-sm-8">
        <h1><?php  echo $file["pagename"];  ?></h1>
<?php  echo $file["title"]; ?>
<?php  echo $file["description"]; ?>
        </div>

        </div>
       </div>
</div>
</div>
?>';
fwrite($myfile , $filecontent);
fclose($myfile);
?>

Can anyone please tell me what I have been doing wrong?

Thanks in advance