从数据库提交创建新页面

I've created a chained menu using php and a database, following this tutorial.

The first table content a list of categories like :

CREATE TABLE IF NOT EXISTS `chainmenu_categories` (
    `id_cat` int(4) unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(40) NOT NULL,
    PRIMARY KEY (`id_cat`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;

My second table, the type, like :

CREATE TABLE IF NOT EXISTS `type` (
    `id_type` int(4) unsigned NOT NULL AUTO_INCREMENT,
    `id_cat` int(4) unsigned NOT NULL,
    `name` varchar(40) NOT NULL,
    `destination` varchar(40) NOT NULL,
    PRIMARY KEY (`id_type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;

I managed, once clicking on submit, to redirect to another page by that in my select.php:

var result = $("select#type option:selected").html(); 
$("#select_form").submit(function( event ) { 
  var the_url = $("#type").val(); 
  window.location = the_url; 
  event.preventDefault(); 
});  

and adding this on my select.class.php

public function ShowCategory() 
{ 
    $sql = "SELECT * FROM chainmenu_categories"; 
    $res = mysql_query($sql,$this->conn); 
    $category = '<option value="0">choose...</option>'; 
    while($row = mysql_fetch_array($res)) 
    { 
        $category .= '<option value="' . $row['id_cat'] . $row['destination']. '">' . $row['name'] . '</option>'; 
    } 
    return $category; 
}

So now it redirects each time to a different page depending of the option choose from the menu, like http://mydomain.com//3 then 4, 5, 6, etc.

But as the page doesn't exist, it redirects to a dead link.

Can someone give me help to create these pages from the chained menu (or have some highlight)? and if possible, some pointer to create the admin interface to allow an admin to add the pages and categories to the chained menu?

I've been trying to start with something which look like:

PHP Code:

<?php require('db_config.php');  

$stmt = $db->prepare('SELECT id_type, name FROM type WHERE id_cat=$_POST[id]'); 
$stmt->execute(array(':id_cat' => $_GET['name'])); 
$row = $stmt->fetch();

However, I don't know if this is good at all.

if(file_exists($filename.'.php'))
    echo "file : " . $filename.'.php' . " is exist";
else
{
  $file = fopen($filename.'.php',"w");
  $code="here what U want to write inside the new page.php";
  fwrite($file,$code);
  fclose($file);
}