Cita:
Iniciado por pr0 Sin código no hay nada que hacer. Esto es programación y por mucho que intentes explicar lo que te pasa con todo tipo de detalles, sin código fuente es inútil.
Voy! Normalmente explico y si hay respuesta entonces pongo el código.
formulario.php
Código PHP:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Formulario</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).on("ready",function()
{
$('#lista1').on("change",function()
{
var id = $('#lista1').val();
var metodo = $('#formulario').attr('method')
$.ajax(
{
url:"mostrarpoblaciones.php",
type:metodo,
data:{identidad: id},
success: function(resp)
{
$('#slista').html(resp);
$('#lista2').on('change',function()
{
$('#campos').load('camposformulario.php');
});
},
error: function(jqXHR,estado,error)
{
alert("No se ha podido realizar la consulta a la base de datos, por favor intentelo de nuevo");
}
});
});
});
</script>
</head>
<body>
<form id="formulario" action="introducir.php" method="post">
<table>
<tr>
<td>Seleccione provincia:
<select id="lista1" name="lst1">
<?php
include("obtenerprovincias.php")
?>
</select>
</td>
<td id="slista">
</td>
</tr>
<td>
<td>
<input name="nEmp" type="submit" value="Insertar" />
</td>
</tr>
</table>
</form>
</body>
</html>
obtenerprovincias.php
Código PHP:
<?php
$c=mysql_connect("localhost","root","");
mysql_select_db("clientes",$c);
$consulta="SELECT * FROM lista_provincias";
$completa=mysql_query($consulta,$c);?>
<?php
while ($fila=mysql_fetch_assoc($completa))
{
?>
<option value="<?php echo $fila['id'];?>"><?php echo $fila['opcion'];?></option>
<?php
}
?>
mostrarpoblaciones.php
Código PHP:
<?php
$c=mysql_connect("localhost","root","");
mysql_select_db("clientes",$c);
$id=$_POST['identidad'];
$consulta="SELECT DISTINCT id, opcion FROM lista_poblaciones WHERE id = $id ORDER BY opcion ASC";
$completa=mysql_query($consulta,$c);?>
Seleccione Población:
<select id="lista2" name="lst2">
<?php
while ($fila=mysql_fetch_assoc($completa))
{
?>
<option value="<?php echo $fila['opcion'];?>"><?php echo $fila['opcion'];?></option>
<?php
}
?>
</select>
introducir.php
Código PHP:
<?php
$c=mysql_connect("localhost","root","");
mysql_select_db("clientes",$c);
$provincia = $_POST['lst1'];
echo $provincia;
echo "<br>";
$poblacion = $_POST['lst2'];
echo $poblacion;
echo "<br>";
mysql_query("insert into tabla.Provincia values (".$provincia.")",$c);
?>