este es el archivo de inserción de municipios que tengo:
Código PHP:
   <?php
require("aut_verifica.inc.php");
$nivel_acceso=0; // Nivel de acceso para esta pАgina.
// se chequea si el usuario tiene un nivel inferior
// al del nivel de acceso definido para esta pАgina.
// Si no es correcto, se mada a la pАgina que lo llamo con
// la variable de $error_login definida con el n╨ de error segun el array de
// aut_mensaje_error.inc.php
if ($nivel_acceso < $_SESSION['usuario_nivel'])
{
header ("Location: $redir?error_login=5");
exit;
}
?>
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Sistema del Herbario Universitario Port</title>
        <link rel="stylesheet" href="css/template_css.css" type="text/css" />
        <link rel="stylesheet" href="css/theme.css" type="text/css" />
        <script language="JavaScript" src="js/JSCookMenu_mini.js" type="text/javascript"></script>
        <script language="JavaScript" src="js/theme.js" type="text/javascript"></script>
        <script type="text/javascript" SRC="js/lib_javascript.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF8" />
        <link rel="shortcut icon" href="images/favicon.png" />
 
        <style type="text/css">
            @import url(css/admin_login.css);
        </style>
 
        <script type="text/javascript" SRC="js/ajax.js"></script>
        <script language="javascript" type="text/javascript">
        function cargarContenidoEstado()
        {
        var d1,contenedor;
        contenedor = document.getElementById('contenedor2');
            d1 = document.QForm.pais.options[document.QForm.pais.selectedIndex].value;
            d2=location.href;
            ajax=nuevoAjax();
            ajax.open("GET", "procesos.php?pais="+d1+"&dir="+d2,true);
            ajax.onreadystatechange=function()
            {
                if (ajax.readyState==4)
                {
                   contenedor.innerHTML = ajax.responseText
                }
            }
        ajax.send(null)
        }        
        </script>
    </head>
 
<body>
<div id="wrapper">
    <div id="header">
            <div id="joomla">
                <img src="css/images/header_text.png" alt="Sistema del Herbario Universitario Port" />
            </div>
    </div>
</div>
 
 
<?php
    include_once("tb_top_menu.html");
?>
 
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="menudottedline" width="75%">
            <div class="pathway">
                <a href="index2.php">
                    <strong>Sistema del Herbario Universitario Port
                    </strong>
                </a> / Municipio / Nuevo
            </div>
        </td>
 
        <td class="menudottedline" align="right" style="padding-right:5px;">
            <font color="blue" size="+2">
            <?php
                $hora=date("h").":".date("i")." ".date("a");
                echo $hora;
            ?>
            </font>
        </td>
 
        <td class="menudottedline" align="right">
            <table cellpadding="0" cellspacing="0" border="0" id="toolbar">
                <tr valign="middle" align="center">
                    <td>
                        <a class="toolbar" href="index2.php" title="Cerrar">
                        <img src="images/cancel_f2.png" alt="Salir" align="middle" name="Salir" border="0" title="Cerrar"/><br />Cerrar</a>
                    </td>
 
                    <td>
                        <a class="toolbar" href="" onclick="javascript:window.open('help.php','','width=640px,height=480px, top=20px, left=30px, resizable=YES, titlebar=YES, Urlbar=NO, Toolbar=NO, ScrollbarS=YES, Directories=NO, Status=YES, menubar=NO')">
                        <img src="images/help_f2.png" alt="Help" align="middle" name="help" border="0" />                <br />Ayuda</a>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
 
<br />
 
<div align="center" class="centermain">
    <div class="main">  
        <div align="center">
            <font color="red" style="text-decoration:blink;">
                <?php echo $error_accion_ms[$error_cod];?>
            </font>
       </div>
       
<!--este es la cabezara que me indica en que parte del sistema estoy-->
<table class="adminheading">
    <tr>
        <th class="municipioadmin">
            Municipio:
            <small>
                Nuevo
            </small>
        </th>
    </tr>
</table>
    
<?php
if (isset($_POST[save]))
{
$cod_municipio = $_POST['cod_municipio'];
$cod_pais = $_POST['pais'];
echo $cod_estado = $_POST['estado'];
$nombre_municipio = $_POST['nombre_municipio'];
    if (($nombre_municipio==""))
        $error="Error: Datos incompletos";
    else
        {
            $error="bien";
            require("aut_config.inc.php");
            /*este es el enlace de conexion a la base de datos*/
            $db_conexion=pg_connect("host=$sql_host dbname=$sql_db user=$sql_usuario password=$sql_pass");
 
            /*este es el llamado a la funcion que inserta los datos a la base de datos*/
 
            $insertar_municipio = pg_query("SELECT insert_municipio($cod_municipio,$cod_estado,'$nombre_municipio')") or die("No se pudo insertar el municipio en la Base de datos");
            $result_insert=pg_fetch_array($insertar_municipio);
            $resultado_insert=$result_insert[0];
            pg_free_result($insertar_municipio);
        }
}//fin del add
?>
 
<!--aqui es donde esta el diseño del formulario-->
    <table class="adminform" border="1">
        <tr>
            <th colspan="2">
                Registro de un Nuevo Municipio
            </th>
        </tr>
        
        <?php
            if ((isset($_POST[save])) and ($error=="bien"))
            {
        ?>
 
        <tr>
            <td colspan="2" align="center">
                <br />
                <strong>Resultado</strong>:
                <?php
                switch($resultado_insert)
                    {
                        case 0: 
                            echo 'No se pudo registrar el Municipio porque ya está registrada en el sistema ';
                            break;
                        case 1: 
                            echo 'El Municipio fue registrado con éxito';    
                            break;
                        case 2: 
                            echo 'El Municipio fue registrado correctamente';
                    }
                    echo '<br />'.$msg;
                ?>
                <br>
            </td>
        </tr>
        
        <?php
            }
                else
            {
        ?>
        
        <form action="municipio_add" method="POST" name="QForm" enctype="multipart/form-data">
        <tr>
            <td colspan="2" align="center">
                <font color="red"><?php echo $error ?></font>
            </td>
        </tr>
        
        <tr>
            <td class="rowformleft" colSpan="2" width="700"  height="16">
                <span class="font_form_est_prof_small">Los campos con <font color="Red">(*)</font> son obligatorios</span>
            </td>
        </tr>
 
        <tr>
            <td  class="rowformleft" width="15%" height="22">
                <span class="font_form_est_prof">Codigo del Municipio<font color="Red">(*)</font></span>
            </td>
 
            <td  class="rowformleft" width="85%"  height="22">
                <input class="font_form_est_prof" type="text" name="cod_municipio" value="<?if ($error!="") echo $codigo;?>" />
            </td>
        </tr>
 
        <tr>
            <td  class="rowformleft" width="172" height="22">
                <span class="font_form_est_prof">Pais<font color="Red">(*)</font></span>
            </td>
 
            <td  class="rowformleft" width="489"  height="22">
                <div id="contenedor1">
                    <SELECT name="pais" onchange="cargarContenidoEstado()" style="width:200px" >
                        <option value="null">------</option>
                        <?php
                            $db_conexion=pg_connect("host=$sql_host dbname=$sql_db user=$sql_usuario password=$sql_pass");
                            $pais=pg_query("select * from pais order by nombre_pais");
                            while ($array_pais=pg_fetch_array($pais))
                                {
                                    echo '<option value="'.$array_pais[0].'">'.$array_pais[1].'</option>';
                                }
                            pg_free_result($pais);
                        ?>
                    </SELECT> 
                </div>
            </td>
        </tr>
    
        <tr>
            <td  class="rowformleft" width="172" height="22">
                <span class="font_form_est_prof">Estado:<font color="Red">(*)</font></span>
            </td>
 
            <td  class="rowformleft" width="489"  height="22">
                <div id="contenedor2">
                    <select name="estado" style="width:200px" >
                        <option value="null">---</option>
                    </select> 
                </div>
            </td>
        </tr>
 
        <tr>
            <td  class="rowformleft" width="15%" height="22">
                <span class="font_form_est_prof">Nombre del Municipio<font color="Red">(*)</font></span>
            </td>
 
            <td  class="rowformleft" width="85%"  height="22">
                <input type="text" id="1" maxLength="50" size="50" name="nombre_municipio">
            </td>
        </tr>
 
        <?php
            require("aut_config.inc.php");
            $db_conexion=pg_connect("host=$sql_host dbname=$sql_db user=$sql_usuario password=$sql_pass");
        ?>
 
        <tr>
            <td colspan="2" align="center">
                <input type="submit" name="save" value="  Guardar  " class="button" >
                <input class="button" type="reset" value="Limpiar" name="Refresh">
            </td>
        </tr>
        </form>
        
        <?php
        }
        ?>
    </table> 
</div>
</div>
<br>
<?php require_once("foot.php");?>
</body>
</html>   Código PHP:
   <?php
include("aut_config.inc.php");
require("aut_verifica.inc.php");
$nivel_acceso=10;
 
if ($nivel_acceso <= $_SESSION['usuario_nivel'])
{
    header ("Location: $redir?error_login=5");
    exit;
}
$db_conexionx=pg_connect("host=$sql_host dbname=$sql_db user=$sql_usuario password=$sql_pass");
 
$pais=$_GET["pais"];
$url=$_GET["dir"];
if (($pais!="")&&($pais!="null")) 
{
 
 
echo '<select name="estado">';
 
if (ereg('registrar', $url)  || ereg('editar', $url))
{
echo 'onChange="cargarContenidoMunicipio()"';
}
echo 'style="width:200px" >';
echo "<option value='0'>-- seleccione el estado--</option>";
$consultax1="SELECT * from estado where cod_pais=$pais order by nombre_estado";
 $ejec_consultax1=pg_query($consultax1);
while($vector=pg_fetch_array($ejec_consultax1))
    
  {
    echo "<option value=$vector[0]> $vector[1]</option>";
  }
echo '</select>';
 
pg_free_result($ejec_consultax1);    
}
pg_close($db_conexionx);
?>    
 

