Código HTML:
<!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> function agregar() { campo = '<li><label>Email:</label><input type="text" size="20" name="email[]" /></li>'; $("#emails").append(campo); } </script> </head> <body> <fieldset id="form"> <legend>Info</legend> <form name="frm_multiple" method="post" action="procesar.php"> <ol> <li> <label>Nombre:</label><input type="text" size="20" name="nombre" /> </li> <li> <label>Asunto:</label><input type="text" size="20" name="asunto" /> </li> <li> <label>Mensaje:</label><input type="text" size="20" name="mensaje" /> </li> <li> <label>Dirección:</label><input type="text" size="30" name="direccion" /> </li> </ol> <ol id="emails"> <li> <label>Email:</label><input type="text" size="20" name="email[]" /> <span><a href="#" onclick="agregar();">Agregar</a></span> </li> </ol> <p align="center"><input type="submit" name="Send" value="Send" /></p> </form> </fieldset> <p align="center"> </p> </body> </html>
El cual tengo la opción para agregar varios emails (inputs dinamicos)
Estoy tratando de procesar la informacion para insertarla a mi base de datos
la cual tiene los sig. campos
id
nombre
asunto
mensaje
Para procesar mis datos tengo el sig. php
Código PHP:
<?php
$hostname_connection = "localhost";
$database_connection = "ces";
$username_connection = "root";
$password_connection = "";
$con = mysql_pconnect($hostname_connection, $username_connection, $password_connection) or trigger_error(mysql_error(),E_USER_ERROR);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$emails=$_POST['email'];
$nombre=$_POST['nombre'];
for ($i=0; $i<=count($emails); $i++) {
echo $emails[$i].'<br>';
//// aqui grabamos en la base de datos o lo que deseemos
$sql="INSERT INTO prueba (nombre, email, asunto, mensaje) VALUES ('$_POST[nombre]','$_POST[emails][$i]','$_POST[asunto]','$_POST[mensaje]')";
}
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Datos insertados";
mysql_close($con);
?>
haciendolo así si agrego dos inputs para email ... me lo registra asi
nombre email asunto mensaje
Angel Villa [2] pago deposito enero
![Negacion](http://static.forosdelweb.com/fdwtheme/images/smilies/negacion.gif)
![lloron](http://static.forosdelweb.com/fdwtheme/images/smilies/chillando.png)
Gracias por su ayuda