Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/08/2014, 14:07
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 en una bd

hola quisiera que me ayudaran, necesito guardar el id delos select en una tabla en especifico
aqui los codigos

este codigo es el formulario en el que se muestran los select
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>

</head>

<body>
<br><br>
<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>
codigo de los select
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>";
}
?>
quisiera guardar el id del segundo select en una tabla en caso de que eligieran comunidad
y el del ultimo en caso de que fuera colonia con su calle