Ver Mensaje Individual
  #7 (permalink)  
Antiguo 05/03/2012, 16:18
Avatar de dvbeaumont
dvbeaumont
 
Fecha de Ingreso: marzo-2011
Ubicación: Caracas
Mensajes: 145
Antigüedad: 13 años, 10 meses
Puntos: 1
Respuesta: Insert en un While

Pues parece que si esta tomando los datos pero mira lo que me genera:

Mi html es:

Código HTML:
Ver original
  1. <form id="form" action="upload-tagarticulo.php"  enctype="multipart/form-data" method="post" autocomplete="off">
  2.                     <fieldset>
  3.                         <section>
  4.                             <label for="multiselect">Tags <br><span><a href='cargar-tag.php'>Crear nuevo </a></span></label>
  5.                             <div>                  
  6.                                 <select name="tag[]" id="multiselect" multiple>
  7.                                         <?php
  8.                             $result_ti=mysql_query("select * from t_tag ORDER BY id_tag",$link);                           
  9.                             while($row_t = mysql_fetch_array($result_ti)) {
  10.                             echo"<option value='".$row_t["id_tag"]."'>".$row_t["titulo"]."</option>";}
  11.                             ?>
  12.                             </select>
  13.                             </div>
  14.                         </section>
  15.                         <input type='hidden' name='id_articulo' value='<?php echo"".$row[0].""?>' />
  16.                         <section>
  17.                             <div><button class="reset">Reset</button><button class="submit" name="submitbuttonname" value="submitbuttonvalue">Enviar</button></div>
  18.                         </section>
  19.                     </fieldset>
  20.                 </form>

el php es

Código PHP:
Ver original
  1. //VERIFICAMOS DE NUEVO QUE SE SELECCIONO ALGUN ARCHIVO
  2. if ( $archivo != "none" ){
  3.  
  4.     //CREAMOS NUESTRO INSERT
  5.     foreach( $_POST['tag'] as $valor ) {
  6.     $qry .= "INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES
  7.    (  '".$valor."', '".$_POST["id_articulo"]."');";  
  8.                                 }
  9.                                
  10.                                
  11.                              
  12.  
  13.     //NOS CONECAMOS A LA BASE DE DATOS
  14.     //REMPLAZEN SUS VALOS POR LOS MIOS
  15. mysql_connect("localhost"," "," ") or die("No se pudo conectar a la base de datos");
  16.    
  17.     //SELECCIONAMOS LA BASE DE DATOS CON LA CUAL VAMOS A TRABAJAR CAMBIEN EL VALOR POR LA SUYA
  18.    
  19.     //EJECUTAMOS LA CONSULTA
  20.     mysql_query($qry) or die("Query: $qry <br />Error: ".mysql_error());
  21.    
  22.     //CERRAMOS LA CONEXION
  23.     mysql_close();
  24.     //NOTIFICAMOS AL USUARIO QUE EL ARCHVO SE HA ENVIADO O REDIRIGIMOS A OTRO LADO ETC.
  25.     echo "  <script language=javascript>
  26.     alert('Comentario hecho satisfactoriamente')
  27.     </script>";
  28.     include_once ("lista-articulos.php");
  29. }else{
  30.     echo "  <script language=javascript>
  31.     alert('No fue posible cargar el comentario, intente de nuevo')
  32.     </script>";
  33.     include_once ("lista-articulos.php");
  34. }

y el error que da es:

Query: INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '1', '16');INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '2', '16');INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '3', '16');INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '4', '16');INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '5', '16');
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '2', '16');INSER' at line 2

Pero no veo cual es...
__________________
Sé parte de nuestro mundo creativo.

http://bbcreativos.com