Ver Mensaje Individual
  #6 (permalink)  
Antiguo 06/05/2014, 19:40
relampago846
 
Fecha de Ingreso: mayo-2014
Ubicación: valparaiso, chile
Mensajes: 34
Antigüedad: 10 años
Puntos: 0
Pregunta Respuesta: como hago un array para selecciones multiples

Cita:
Iniciado por caricatos Ver Mensaje
Hola:

Cuando agregas un juego de corchetes a los campos, estás indicando que envías un array, así que luego debes procesar ese campo como un array, por ejemplo convirtiéndolo en una cadena con un implode... y comprobar antes su existencia por si no se selecciona ninguna opción...

Por cierto, la funcionalidad de un select múltiple es la misma que una serie de checkboxes con el mismo nombre (y también con su juego de corchetes).

Saludos
Cita:
Iniciado por caricatos Ver Mensaje
Hola:

Por lo que veo, las líneas serían:

$cates = (isset($_POST["intCategoria"])) ? "categoria='".implode(",", $_POST["intCategoria"])."'," : "";

$sql "update $tabla set $cates otrosCampos='$otrosValores' ...";

Saludos

esto me arroja error de sintaxis:
Código PHP:
Ver original
  1. $sql "update $tabla set $cates otrosCampos='$otrosValores' ...";

creo que es porque tengo que cambiar algun valor de lo que tu me diste pero no se cual es

no se si esto ayude pero aqui esta el codigo completo:

Código PHP:
Ver original
  1. <?php require_once('../Connections/conexion_pelislatino.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39.  
  40. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  41.   $insertSQL = sprintf("INSERT INTO tblpelicula (strNombre, intCategoria, strImagen, strSinopsis, strInfo, strLinks) VALUES (%s, %s, %s, %s, %s, %s)",
  42.                        GetSQLValueString($_POST['strNombre'], "text"),
  43.                        GetSQLValueString($_POST['intCategoria'], "int"),
  44.                        GetSQLValueString($_POST['strImagen'], "text"),
  45.                        GetSQLValueString($_POST['strSinopsis'], "text"),
  46.                        GetSQLValueString($_POST['strInfo'], "text"),
  47.                        GetSQLValueString($_POST['strLinks'], "text"));
  48.  
  49.   mysql_select_db($database_conexion_pelislatino, $conexion_pelislatino);
  50.   $Result1 = mysql_query($insertSQL, $conexion_pelislatino) or die(mysql_error());
  51.  
  52.   $insertGoTo = "peliculas_lista.php";
  53.   if (isset($_SERVER['QUERY_STRING'])) {
  54.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  55.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  56.   }
  57.   header(sprintf("Location: %s", $insertGoTo));
  58. }
  59.  
  60. mysql_select_db($database_conexion_pelislatino, $conexion_pelislatino);
  61. $query_consulta_categorias = "SELECT * FROM tblcategoria ORDER BY tblcategoria.strDescripcion ASC";
  62. $consulta_categorias = mysql_query($query_consulta_categorias, $conexion_pelislatino) or die(mysql_error());
  63. $row_consulta_categorias = mysql_fetch_assoc($consulta_categorias);
  64. $totalRows_consulta_categorias = mysql_num_rows($consulta_categorias);
  65. ?>
  66. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  67. <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/baseadmin.dwt.php" codeOutsideHTMLIsLocked="false" -->
  68. <head>
  69. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  70. <!-- InstanceBeginEditable name="doctitle" -->
  71. <title>admin</title>
  72. <!-- InstanceEndEditable -->
  73. <!-- InstanceBeginEditable name="head" -->
  74. <script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
  75. <link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
  76. <!-- InstanceEndEditable -->
  77. <link href="../estilo/baseadmin.css" rel="stylesheet" type="text/css" />
  78. </head>
  79.  
  80. <body>
  81.  
  82. <div class="container">
  83.   <div class="header"><!-- end .header -->
  84.     <p><img src="http://www.forosdelweb.com/f18/images/diseño/foto%20principal%20web.JPG" width="943" height="201" alt="logo" /></p>
  85.   </div>
  86.   <div class="sidebar1">
  87.   <?php include("../includes/cabeceraadmin.php");
  88.   ?>
  89.     <ul class="nav">
  90.       <li></li></ul>
  91.     <!-- end .sidebar1 --></div>
  92.   <div class="content">
  93.     <h1><!-- InstanceBeginEditable name="encabezado" -->añadir pelicula<!-- InstanceEndEditable --></h1>
  94.     <!-- InstanceBeginEditable name="contenido" -->
  95.    
  96.     <script>
  97. function subirimagen()
  98. {
  99.         self.name = 'opener';
  100.         remote = open('gestionimagen.php', 'remote',
  101.         'width=400,heighht=150,location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes,fullscreen=no, status=yes');
  102.         remote.focus();
  103.         }
  104.    
  105.     </script>
  106.    
  107.     <p>&nbsp;</p>
  108.     <p>&nbsp;</p>
  109.     <form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
  110.       <table align="center">
  111.         <tr valign="baseline">
  112.           <td width="86" align="right" nowrap="nowrap">Nombre:</td>
  113.           <td width="271"><span id="sprytextfield1">
  114.             <input type="text" name="strNombre" value="" size="32" />
  115.           <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
  116.         </tr>
  117.         <tr valign="baseline">
  118.           <td nowrap="nowrap" align="right">Imagen:</td>
  119.           <td><label for="strImagen"></label>
  120.             <span id="sprytextfield2">
  121.             <input type="text" name="strImagen" id="strImagen" />
  122.           <span class="textfieldRequiredMsg">Se necesita un valor.</span></span>            <input type="button" name="button" id="button" value="subir imagen" onclick="javascript:subirimagen();"/></td>
  123.         </tr>
  124.         <tr valign="baseline">
  125.           <td nowrap="nowrap" align="right">Categoria:</td>
  126.           <td><label for="intCategoria[]"></label>
  127.             <select name="intCategoria[]" size="1" multiple="MULTIPLE" id="intCategoria[]">
  128.             <?php $cates = (isset($_POST["intCategoria"])) ? "categoria='".implode(",", $_POST["intCategoria"])."'," : "";
  129.  
  130. $sql "update $tabla set $cates otrosCampos='$otrosValores' ...";
  131. ?>
  132.               <?php
  133. do {  
  134. ?>
  135.               <option value="<?php echo $row_consulta_categorias['idCategoria']?>"><?php echo $row_consulta_categorias['strDescripcion']?></option>
  136.               <?php
  137. } while ($row_consulta_categorias = mysql_fetch_assoc($consulta_categorias));
  138.   $rows = mysql_num_rows($consulta_categorias);
  139.   if($rows > 0) {
  140.       mysql_data_seek($consulta_categorias, 0);
  141.       $row_consulta_categorias = mysql_fetch_assoc($consulta_categorias);
  142.   }
  143. ?>
  144.           </select></td>
  145.         </tr>
  146.         <tr valign="baseline">
  147.           <td nowrap="nowrap" align="right">Sinopsis:</td>
  148.           <td><label for="strInfo"></label>
  149.           <input type="text" name="strSinopsis" id="strSinopsis" /></td>
  150.         </tr>
  151.         <tr valign="baseline">
  152.           <td nowrap="nowrap" align="right">Info:</td>
  153.           <td><label for="strInfo"></label>
  154.             <label for="strInfo"></label>
  155.           <textarea name="strInfo" id="strInfo" cols="45" rows="5"></textarea></td>
  156.         </tr>
  157.         <tr valign="baseline">
  158.           <td nowrap="nowrap" align="right">Links:</td>
  159.           <td><label for="strLinks"></label>
  160.           <input type="text" name="strLinks" id="strLinks" /></td>
  161.         </tr>
  162.         <tr valign="baseline">
  163.           <td nowrap="nowrap" align="right">&nbsp;</td>
  164.           <td><input type="submit" value="Insertar pelicula" /></td>
  165.         </tr>
  166.       </table>
  167.       <input type="hidden" name="MM_insert" value="form1" />
  168.       <input type="hidden" name="MM_insert" value="form1" />
  169.     </form>
  170.     <p>&nbsp;</p>
  171.     <script type="text/javascript">
  172. var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
  173. var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
  174.     </script>
  175.     <!-- InstanceEndEditable --><!-- end .content --></div>
  176.   <div class="footer">
  177.     <p>administracion de pelis latino</p>
  178.     <!-- end .footer --></div>
  179.   <!-- end .container --></div>
  180. </body>
  181. <!-- InstanceEnd --></html>
  182. <?php
  183. mysql_free_result($consulta_categorias);
  184. ?>

ayuda plis