Ver Mensaje Individual
  #8 (permalink)  
Antiguo 13/04/2011, 13:53
Avatar de bUllan9ebrio
bUllan9ebrio
 
Fecha de Ingreso: enero-2011
Ubicación: Chile
Mensajes: 1.128
Antigüedad: 13 años, 3 meses
Puntos: 128
Respuesta: Guardar combobox (select) en mi bd

Prueba con esto:

Código PHP:
Ver original
  1. <?php
  2. include("config.php");
  3. echo '<html>
  4. <body>
  5. <h1><center>
  6. <p>AGREGA BIENES</p>
  7. </center></h1>
  8. <form action="crea_bienes.php" method="POST">
  9.     <div align="center">
  10.         <table width="415"  border="0">
  11.             <tr>
  12.                <td width="169" height="69">
  13.                     NO_INVENTARIO:
  14.                 </td>
  15.                <td width="236">
  16.                     <input name="inventario" type="text"  size=30>
  17.                 </td>
  18.             </tr>
  19.             <tr>
  20.                 <td height="61">
  21.                     DESCRIPCION:
  22.                 </td>
  23.                 <td>
  24.                     <input size=30 type="text" name="descripcion">
  25.                 </td>
  26.             </tr>
  27.             <tr>
  28.                 <td height="60">
  29.                     ESTADO FISICO:
  30.                 </td>
  31.                 <td>
  32.                     <select name="nombre_estado_fisico">
  33.                         <option>Selecciona Estado Fisico </option>';
  34.                             $link=Conectarse();
  35.                             $query="SELECT nombre_estado_fisico FROM estado_fisico";
  36.                             $resultado = mysql_query($query);
  37.                             if ($resultado)
  38.                                 while($renglon = mysql_fetch_array($resultado))
  39.                                 {
  40.                                     $valor=$renglon['nombre_estado_fisico'];
  41.                                     echo '<option value="'.$valor.'">"'.$valor.'"</option>';
  42.                                 }
  43.                                 mysql_close($link);
  44.                     echo'</select>
  45.                 </td>
  46.             </tr>
  47.             <tr>
  48.                 <td height="60">
  49.                     RESGUARDANTE:
  50.                 </td>
  51.                 <td>
  52.                     <select name="nombre_resguardante">
  53.                         <option>Selecciona Resguardante </option>';
  54.                         $link=Conectarse();
  55.                         $query="SELECT nombre_resguardante FROM resguardan";
  56.                         $resultado = mysql_query($query);
  57.                         if ($resultado)
  58.                             while($renglon = mysql_fetch_array($resultado))
  59.                             {
  60.                                 $valor=$renglon['nombre_resguardante'];
  61.                                 echo '<option value="'.$valor.'">"'.$valor.'"</option>';
  62.                             }
  63.                         mysql_close($link);
  64.                     echo'</select>
  65.                 </td>
  66.             </tr>
  67.             <tr>
  68.                 <td height="60">
  69.                     NIVEL:
  70.                 </td>
  71.                 <td>
  72.                     <select name="nivel">
  73.                         <option>Selecciona Nivel </option>';
  74.                         $link=Conectarse();
  75.                         $query="SELECT nivel FROM niveles";
  76.                         $resultado = mysql_query($query);
  77.                         if ($resultado)
  78.                         while($renglon = mysql_fetch_array($resultado))
  79.                         {
  80.                             $valor=$renglon['nivel'];
  81.                             echo '<option value="'.$valor.'">"'.$valor.'"</option>';
  82.                         }
  83.                         mysql_close($link);
  84.                     echo'</select>
  85.                 </td>
  86.             </tr>
  87.             <tr>
  88.                 <td height="60">
  89.                     SECCIONES:
  90.                 </td>
  91.                 <td>
  92.                     <select name="nombre_seccion">
  93.                         <option>Selecciona Seccion </option>';
  94.                         $link=Conectarse();
  95.                         $query="SELECT nombre_seccion FROM secciones";
  96.                         $resultado = mysql_query($query);
  97.                         if ($resultado)
  98.                         while($renglon = mysql_fetch_array($resultado))
  99.                         {
  100.                             $valor=$renglon['nombre_seccion'];
  101.                             echo '<option value="'.$valor.'">"'.$valor.'"</option>';
  102.                         }
  103.                         mysql_close($link);
  104.                     echo'</select>
  105.                 </td>
  106.             </tr>
  107.             <tr>
  108.                 <td colspan="2" align="center">
  109.                     <a href="modificar.php">Volver al Menu </a>
  110.                 </td>
  111.                 <td height="55" colspan="2" align="center">
  112.                     <input type="submit" name="Guardar">
  113.                 </td>
  114.             </tr>
  115.         </table>
  116.         <h5> . . . Escribir en mayusculas . . .</h5>
  117.     </div>
  118. </form>
  119. </body>
  120. </html>';
  121. ?>

y recibes :

Código PHP:
Ver original
  1. <?php
  2.       include("config.php");
  3.       $link = Conectarse();
  4.       $no_inventario = htmlspecialchars(trim($_POST['inventario']));
  5.       $descripcion = htmlspecialchars(trim($_POST['descripcion']));
  6.       $estado_fisico= htmlspecialchars(trim($_POST['nombre_estado_fisico']));
  7.       $resguardante= htmlspecialchars(trim($_POST['nombre_resguardante']));
  8.       $nivel= htmlspecialchars(trim($_POST['nivel']));
  9.       $seccion = htmlspecialchars(trim($_POST['nombre_seccion']));
  10.       $query = sprintf("SELECT no_inventario FROM bienes WHERE bienes.no_inventario='%s'",
  11.       mysql_real_escape_string($no_inventario));
  12.       $result=mysql_query($query,$link);
  13.       if(mysql_num_rows($result))
  14.         {
  15.          echo "El numero de inventario ya existe en la BD";
  16.         }
  17.                     if($no_inventario==NULL|$descripcion==NULL|$estado_fisico==NULL|$resguardante==NULL|$nivel==NULL|$seccion==NULL)
  18.                     {
  19.                     echo "<center><b><h4>Uno o mas campos estan vacios,&nbsp;&nbsp; verifica bien tus datos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h4></b></center>";
  20.                     echo '<center><b><a href="agregar_bienes.php">Volver</b></center></a>';
  21.                     }
  22.                          else
  23.                              {                                                                        
  24.                                 $query = sprintf("INSERT INTO bienes (no_inventario, descripcion, estado_fisico, resguardante, nivel, seccion) VALUES ('%s','%s','%s', '%s','%s','%s')",
  25.                                  mysql_real_escape_string($no_inventario),
  26.                                  mysql_real_escape_string($descripcion),
  27.                                  mysql_real_escape_string($estado_fisico),
  28.                                  mysql_real_escape_string($resguardante),
  29.                                  mysql_real_escape_string($nivel),
  30.                                  mysql_real_escape_string($seccion));            
  31.                                  $result=mysql_query($query,$link);
  32.                                  header('Location:modificar.php');
  33.                                  if(mysql_affected_rows())
  34.                                     {
  35.                                       echo "Los datos han sido correctamente insertados";
  36.                                     }
  37.                                       else
  38.                                         {
  39.                                           echo "Error introduciendo los datos";
  40.                                         }
  41.                             }
  42.       ?>

Fijate que tenias error en los option, problemas con las " y al momento de recibir igual, no veo la necesidad de utilizar Js saludos.
__________________
Si no vivimos como pensamos, pronto empezaremos a pensar como vivimos.
Más vale un Gracias sincero, que un número que aumente "popularidad" ¬¬°

Universidad de chile, campeón