Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/03/2012, 08:25
Avatar de dvbeaumont
dvbeaumont
 
Fecha de Ingreso: marzo-2011
Ubicación: Caracas
Mensajes: 145
Antigüedad: 13 años, 1 mes
Puntos: 1
Exclamación Insertar multiples filas con foreach

Buenas tengo este codigo:

Código PHP:
//VERIFICAMOS DE NUEVO QUE SE SELECCIONO ALGUN ARCHIVO
if ( $archivo != "none" ){

     
//CREAMOS NUESTRO INSERT
    
foreach( $_POST['tag'] as $valor ) {
    
$qry .= "INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES
    (  '"
.$valor."', '".$_POST["id_articulo"]."' )";";";  
                                }
                                
    
//NOS CONECAMOS A LA BASE DE DATOS
    //REMPLAZEN SUS VALOS POR LOS MIOS
mysql_connect("localhost"," "," ") or die("No se pudo conectar a la base de datos");
    
    
//SELECCIONAMOS LA BASE DE DATOS CON LA CUAL VAMOS A TRABAJAR CAMBIEN EL VALOR POR LA SUYA
mysql_select_db(" ");
    
    
//EJECUTAMOS LA CONSULTA
    
mysql_query($qry) or die("Query: $qry <br />Error: ".mysql_error());
    
    
//CERRAMOS LA CONEXION
    
mysql_close();
    
//NOTIFICAMOS AL USUARIO QUE EL ARCHVO SE HA ENVIADO O REDIRIGIMOS A OTRO LADO ETC.
    
echo "    <script language=javascript>
    alert('Comentario hecho satisfactoriamente')
    </script>"
;
    include_once (
"lista-articulos.php");
}else{
    echo 
"    <script language=javascript>
    alert('No fue posible cargar el comentario, intente de nuevo')
    </script>"
;
    include_once (
"lista-articulos.php");

Sucede que ingreso mediante un select multiple con name='tag[]'

Varios datos, parece reconocerlos pero arroja este error:

Query: INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '1', '19' )INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '2', '19' )INSERT INTO t_tag_articulo (id_tag, id_articulo) VALUES ( '3', '19' )
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', '19' )INSER' at line 2

Quisiera saber cual es el problema de esa consulta para insertar varios datos
__________________
Sé parte de nuestro mundo creativo.

http://bbcreativos.com