Ver Mensaje Individual
  #6 (permalink)  
Antiguo 16/11/2018, 19:09
Avatar de davincci
davincci
 
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Respuesta: Insertar varios registros en una tabla

He estado realizado el trabajo pero no logro hacer que se inserte los registros como debe ser, alguine puede ayudarme a ver donde esta mi error, creo que esta en la parte de $res=mysql_query("INSERT INTO personas (cod, nombre) VALUES ('".$value."','".$value."')");

Dejo el codigo de lo que he realizado.

Código:
<?php
include 'conexion.php';

$con=conexion();

$res=mysql_query("select * from personas",$con);

?>

<!DOCTYPE html>
<html>
<body>

<h1>Insertar Datos</h1>

<form method="post" action="insertar.php">

<table border="1″>

<tr>
<th></th> 
<th>Codigo</th> 
<th>Nombre</th> 
</tr>

<?php 
while($fila=mysql_fetch_array($res)){
?>
<tr>
<th><input type="checkbox" name="casilla[]" value="<?php echo $fila[cod]; ?>"><td width="95" height="44"></th> 
<th><label for="cod"></label>
    <input name="cod[]" type="text" id="cod" value="<?php echo $fila[cod]; ?>"></th> 
<th width="98"><label for="nombre"></label>
  <input name="nombre[]" type="text" id="nombre" value="<?php echo $fila[nombre]; ?>"></th> 
</tr>
<?php
}
?>

</table>
<input type="submit" value="insertar" />
</form>
</body>
</html>

Código:
<?php
include 'conexion.php';

$con=conexion();

$x=$_POST[casilla];

foreach ($x as $value){



$res=mysql_query("INSERT INTO personas (cod, nombre) VALUES ('".$value."','".$value."')");

if($res){

echo 'insercion de datos correctamente<br/>';

}

}

?>

<a href="index.php">Volver</a>
__________________
Mil gracias por sus enseñanzas.

Davincci