Ver Mensaje Individual
  #3 (permalink)  
Antiguo 12/04/2011, 09:10
Avatar de Ximenitaa
Ximenitaa
 
Fecha de Ingreso: abril-2011
Ubicación: Mexico
Mensajes: 208
Antigüedad: 13 años
Puntos: 43
Respuesta: Guardar combobox (select) en mi bd

Gracias !!
Este es el utilizo para el formulario

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


y este para guardar los datos ....

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


El segundo se que esta mal porque de antemano estoy usando el codigo para text y no para
combo, agradeceria tu ayuda !!

GRacias !!
__________________
❤(。◕‿◕)❤ . . . Ten un dia .... GeNiAl.... !!!! . . . ❤(◕‿◕。)❤

¿Que dia es hoy? . . . Hoy, hoy, es definitivamente un dia PERFECTO !!

Última edición por Ximenitaa; 12/04/2011 a las 09:18