seleccionar mas de una categoria con select multiple
Publicado por daniel (50 intervenciones) el 13/05/2014 05:41:24
hola a todos soy nuevo en este foro y también en php....
tengo una consulta espero que me puedan ayudar...
estoy haciendo una web de películas en las que hay películas que van en mas de una categoría, pero resulta que cuando elijo mas de una categoría solo me agrega la ultima , me dijeron que era porque hay que hacer un array
cosa que no se hacer y es lo único que me falta para completar mi web en php, aquí esta el código completo:
por favor espero su ayuda, ademas les repito que no se mucho de php, así que si puede alguien pasarme el codigo
faltante que lo haga lo mas parecido a como debería ser please
de antemano gracias
me falto decir que el campo intCategoria es un entero
PD: espero que no piensen que me gusta que me den todo en bandeja , pero la verdad ya llevo un mes sin encontrar la solucion a esto...
tengo una consulta espero que me puedan ayudar...
estoy haciendo una web de películas en las que hay películas que van en mas de una categoría, pero resulta que cuando elijo mas de una categoría solo me agrega la ultima , me dijeron que era porque hay que hacer un array
cosa que no se hacer y es lo único que me falta para completar mi web en php, aquí esta el código completo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php require_once('../Connections/conexion_pelislatino.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tblpelicula (strNombre, intCategoria, strImagen, strSinopsis, strInfo, strLinks) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['strNombre'], "text"),
GetSQLValueString($_POST['intCategoria'], "int"),
GetSQLValueString($_POST['strImagen'], "text"),
GetSQLValueString($_POST['strSinopsis'], "text"),
GetSQLValueString($_POST['strInfo'], "text"),
GetSQLValueString($_POST['strLinks'], "text"));
mysql_select_db($database_conexion_pelislatino, $conexion_pelislatino);
$Result1 = mysql_query($insertSQL, $conexion_pelislatino) or die(mysql_error());
$insertGoTo = "peliculas_lista.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_conexion_pelislatino, $conexion_pelislatino);
$query_consulta_categorias = "SELECT * FROM tblcategoria ORDER BY tblcategoria.strDescripcion ASC";
$consulta_categorias = mysql_query($query_consulta_categorias, $conexion_pelislatino) or die(mysql_error());
$row_consulta_categorias = mysql_fetch_assoc($consulta_categorias);
$totalRows_consulta_categorias = mysql_num_rows($consulta_categorias);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/baseadmin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>admin</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
<link href="../estilo/baseadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<div class="header"><!-- end .header -->
<p><img src="../images/diseño/foto%20principal%20web.JPG" width="943" height="201" alt="logo" /></p>
</div>
<div class="sidebar1">
<?php include("../includes/cabeceraadmin.php");
?>
<ul class="nav">
<li></li></ul>
<!-- end .sidebar1 --></div>
<div class="content">
<h1><!-- InstanceBeginEditable name="encabezado" -->añadir pelicula<!-- InstanceEndEditable --></h1>
<!-- InstanceBeginEditable name="contenido" -->
<script>
function subirimagen()
{
self.name = 'opener';
remote = open('gestionimagen.php', 'remote',
'width=400,heighht=150,location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes,fullscreen=no, status=yes');
remote.focus();
}
</script>
<p> </p>
<p> </p>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td width="86" align="right" nowrap="nowrap">Nombre:</td>
<td width="271"><span id="sprytextfield1">
<input type="text" name="strNombre" value="" size="32" />
<span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Imagen:</td>
<td><label for="strImagen"></label>
<span id="sprytextfield2">
<input type="text" name="strImagen" id="strImagen" />
<span class="textfieldRequiredMsg">Se necesita un valor.</span></span> <input type="button" name="button" id="button" value="subir imagen" onclick="javascript:subirimagen();"/></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Categoria:</td>
<td><label for="intCategoria">
<select name="intCategoria" size="1" multiple="MULTIPLE" id="intCategoria">
<?php do {
?>
<option value="<?php echo $row_consulta_categorias['idCategoria']?>" selected="selected"><?php echo $row_consulta_categorias['strDescripcion']?></option>
<?php
} while ($row_consulta_categorias = mysql_fetch_assoc($consulta_categorias));
$rows = mysql_num_rows($consulta_categorias);
if($rows > 0) {
mysql_data_seek($consulta_categorias, 0);
$row_consulta_categorias = mysql_fetch_assoc($consulta_categorias);
}
?>
</select>
</label></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Sinopsis:</td>
<td><label for="strInfo"></label>
<input type="text" name="strSinopsis" id="strSinopsis" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Info:</td>
<td><label for="strInfo"></label>
<label for="strInfo"></label>
<textarea name="strInfo" id="strInfo" cols="45" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Links:</td>
<td><label for="strLinks"></label>
<input type="text" name="strLinks" id="strLinks" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insertar pelicula" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
</script>
<!-- InstanceEndEditable --><!-- end .content --></div>
<div class="footer">
<p>administracion de pelis latino</p>
<!-- end .footer --></div>
<!-- end .container --></div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($consulta_categorias);
?>
por favor espero su ayuda, ademas les repito que no se mucho de php, así que si puede alguien pasarme el codigo
faltante que lo haga lo mas parecido a como debería ser please
de antemano gracias
me falto decir que el campo intCategoria es un entero
PD: espero que no piensen que me gusta que me den todo en bandeja , pero la verdad ya llevo un mes sin encontrar la solucion a esto...
Valora esta pregunta


0