Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/08/2014, 09:31
Virjikio
 
Fecha de Ingreso: julio-2014
Mensajes: 7
Antigüedad: 9 años, 9 meses
Puntos: 0
Exclamación Guardar el ID de un select dinámico en un base de datos

nesecito ayuda
quiero guardar la id del select 2 en una tabla en caso de que fuera comunidad y guardar la id del select 3 en otra tabla en caso que fuera colonia
los codigos son los siguientes
Código PHP:
<?php
function generaSelect()
{
    include 
'conexion.php';
    
conectar();
    
$consulta=mysql_query("SELECT id, opcion FROM select_1");
    
desconectar();

    
// Voy imprimiendo el primer select compuesto por los paises
    
echo "<select name='select1' id='select1' onChange='cargaContenido(this.id)'>";
    echo 
"<option value='0'>Elige</option>";
    while(
$registro=mysql_fetch_row($consulta))
    {
        echo 
"<option value='".$registro[0]."'>".$registro[1]."</option>";
    }
    echo 
"</select>";
}
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


<html lang="es">
<head>
<link rel='shortcut icon' href="icono.png" type="image/png">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Registro de Productores</title>
<script type="text/javascript" src="jvs/select_dependientes_3_niveles.js"></script>
<link rel="stylesheet" type="text/css" href="css/estilos.css" />
</head>

<body>
<div id="container">
 <form id="formulario" name="formulario" method="post" action="Guardar.php">
 
 <h4>Datos Personales Del Productor</h4>
   <table width="502" height="230">
     <tr>
        <td width="261" height="21" >Nombre </td>
        <td width="261" height="21" >Apellido Paterno </td>
        <td width="229" >Apellido Materno</td>
    </tr>
    <br>
    <tr>
        <td height="30" ><input type="text" name="nombre" id="nombre" class="text-input" style="width:175px" value="<?php echo @$_POST[nombre]?>">
                         </td>
                         
      <td ><input type="text" name="ap" id="ap" style="width:175px" value="<?php echo @$_POST[ap]?>" class="text-input">
                
        </td>
        <td ><input type="text" name="am" id="am" style="width:175px" value="<?php echo @$_POST[am]?>" class="text-input">
                
        </td>
    </tr>
        <tr>
         <td height="21">CURP</td>
        <td>RFC</td>
        <td >Nacionalidad</td>
    </tr>
    <tr><td  height="25"><input type="text" name="curp" id="curp" style="width:175px" value="<?php echo @$_POST[curp]?>" class="text-input">
                
        </td>
        <td ><input type="text" name="rfc" id="rfc" style="width:175px" value="<?php echo @$_POST[rfc]?>" class="text-input">
        
        </td>
        <td ><input type="text" name="nacionalidad" id="nacionalidad" style="width:175px" value="<?php echo @$_POST[nacionalidad]?>" class="text-input">
        
        </td>
   </tr>
   <tr>
        <td height="21" >Estado De Nacimiento</td>
        <td >Genero</td>
   </tr>
   <tr>
        <td height="25" ><input type="text" name="estado_nacimiento" id="estado_nacimiento" style="width:175px" value="<?php echo @$_POST[estado_nacimiento]?>" class="text-input">
        
        </td>
        <td>
       
    <select name="genero" id="genero">
         <option value="Mujer">Mujer</option>
          <option value="Hombre">Hombre</option>
    </select>
     </div>
        </td>
   </tr>
     <tr>
        <td height="40" >Numero De Identificacion (Reverso IFE)</td>
        <td >&nbsp;</td>
   </tr>
   <tr>
        <td width="261" height="27" ><input type="text" name="numero_ife" id="numero_ife" style="width:175px" value="<?php echo @$_POST[numero_ife]?>" class="text-input">
               </td>
        <td width="229" >&nbsp;</td>
    </tr>
  </table>
<br>
<br>

 
 <h4>Datos Del Domicilio Del Productor</h4>
 <br>
 <form id="form1" name="form1" method="post" action="">
 

            
            
                <div id="demoIzq"><?php generaSelect(); ?></div><br>
                <div id="demoMed">
                    <select disabled="disabled" name="select2" id="select2">
                        <option value="0">Selecciona opci&oacute;n...</option>
                    </select>
                </div><br>
                <div id="demoDer">
                    <select disabled="disabled" name="select3" id="select3">
                        <option value="0">Selecciona opci&oacute;n...</option>
                    </select>
                </div>  
            <br>
            <table>
            <tr>
             <td" >Referencia</td>
    </tr>
   
    <tr>
        <td ><input type="text" name="referencia" id="referencia" class="text-input" style="width:175px" value="<?php echo @$_POST[nombre]?>"></tr></td></table>
<br><br>

<input type="submit" value="Guardar" name="ok" id="ok" action="Guardar.php">
<input type="reset" name="Borrar" value="Borrar"/>


</body>
</html>
Código PHP:
<?php
// Array que vincula los IDs de los selects declarados en el HTML con el nombre de la tabla donde se encuentra su contenido
$listadoSelects=array(
"select1"=>"select_1",
"select2"=>"select_2",
"select3"=>"select_3"
);

function 
validaSelect($selectDestino)
{
    
// Se valida que el select enviado via GET exista
    
global $listadoSelects;
    if(isset(
$listadoSelects[$selectDestino])) return true;
    else return 
false;
}

function 
validaOpcion($opcionSeleccionada)
{
    
// Se valida que la opcion seleccionada por el usuario en el select tenga un valor numerico
    
if(is_numeric($opcionSeleccionada)) return true;
    else return 
false;
}

$selectDestino=$_GET["select"]; $opcionSeleccionada=$_GET["opcion"];

if(
validaSelect($selectDestino) && validaOpcion($opcionSeleccionada))
{
    
$tabla=$listadoSelects[$selectDestino];
    include 
'conexion.php';
    
conectar();
    
$consulta=mysql_query("SELECT id, opcion FROM $tabla WHERE relacion='$opcionSeleccionada'") or die(mysql_error());
    
desconectar();
    
    
// Comienzo a imprimir el select
    
echo "<select name='".$selectDestino."' id='".$selectDestino."' onChange='cargaContenido(this.id)'>";
    echo 
"<option value='0'>Elige</option>";
    while(
$registro=mysql_fetch_row($consulta))
    {
        
// Convierto los caracteres conflictivos a sus entidades HTML correspondientes para su correcta visualizacion
        
$registro[1]=htmlentities($registro[1]);
        
// Imprimo las opciones del select
        
echo "<option value='".$registro[0]."'>".$registro[1]."</option>";
    }            
    echo 
"</select>";
}
?>
Código PHP:
<html>
<link rel="stylesheet" type="text/css" href="css/estilos1.css" />
</html>
<?php
$conectado
=mysql_connect("localhost","root","");
mysql_select_db("ajax1",$conectado);
$consulta="SELECT*FROM productor;";
$hacerConsulta=mysql_query($consulta,$conectado);
$hacerConsulta=mysql_query($consulta,$conectado);
$numeroDeRegistros=mysql_num_rows($hacerConsulta);



$nombre=$_POST['nombre'];
$ap=$_POST['ap'];
$am=$_POST['am'];
$curp=$_POST['curp'];
$rfc=$_POST['rfc'];
$nacionalidad=$_POST['nacionalidad'];
$estado_nacimiento=$_POST['estado_nacimiento'];
$genero=$_POST['genero'];
$numero_ife=$_POST['numero_ife'];
$id=$_POST['id'];
$referencia=$_POST['referencia'];





$consulta="INSERT INTO  productor (nombre, ap, am, curp, rfc, nacionalidad, estado_nacimiento, genero, numero_ife)
VALUES ('$nombre','$ap','$am','$curp','$rfc','$nacionalidad','$estado_nacimiento','$genero','$numero_ife');"
;
$hacerConsulta=mysql_query ($consulta$conectado);


$resultado mysql_query("SELECT id FROM select_3 WHERE Nombre='$Seccion'"); 

mysql_query("INSERT INTO direccionespecifica VALUES ('$id', '$curp', '$referencia')");
$hacerConsulta=mysql_query ($consulta$conectado);


if (
$hacerConsulta) {
echo (
"<b><center><h2>SE HAN REGISTRADO LOS DATOS DEL PRODUCTOR");

}
else
{
echo (
"<br><br><b>NO SE REGISTRARON LOS DATOS DEL PRODUCTOR, VERIFIQUE CON SERVICIO AL CLIENTE");
}


?>


si pudieran ayudarme estare agradecido