Ver Mensaje Individual
  #5 (permalink)  
Antiguo 28/04/2011, 18:14
Avatar de floog
floog
 
Fecha de Ingreso: enero-2006
Mensajes: 191
Antigüedad: 18 años, 3 meses
Puntos: 2
Respuesta: agregar y actualizar multiples registros

he estado revisando algunos post y paginas y para hacer el insert en la nueva tabla deberia usar un for... he modificado la hoja de formulario incluyendo un par de campos hidden que envien el id y el numero total de registros identificados al script de insercion de datos,
Código PHP:
<? 
   session_start 
();
   if (isset(
$_SESSION["autentificado"])){ ?>
<html>
   <head>
   <link href="../scripts/css-core.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <? //conectamos a la bbdd
        
include ('../scripts/db-conn.php');
        
$query "SELECT * FROM c_coches WHERE reg='No' ";
        
$sql mysql_query ($query);
        
$num_reg mysql_num_rows ($sql);
    
?>
    <form name="checkin" action="../scripts/checkin.php">
    <table>
        <tr>
            <td>Vehiculo</td>
            <td>Status</td>
            <td>Campa</td>
            <td>Fila</td>
            <td>Posicion</td>
            <td></td>
        </tr>
        <? while ($rows mysql_fetch_array ($sql)) {?>
        <tr>
            <td><? echo $rows ["chasis"]; ?></td>
            <td><select name="status<? echo $rows["vid"]; ?>">
                    <option value="Si">Si</option>
                    <option value="No">No</option>
                </select>
            </td>
            <td><select name="campa<? echo $rows["vid"]; ?>">
                    <option value="Parking">Parking</option>
                    <option value="Ampliacion">Ampliacion</option>
                </select>
            </td>
            <td><input type="text" name="fila<? echo $rows["vid"]; ?>" size="5"></td>
            <td><input type="text" name="posicion<? echo $rows["vid"]; ?>" size="5"></td>
            <td><input type="hidden" name="<? echo $rows["vid"]; ?>"></td>
        <? ?>
        </tr>
        <tr>
            <td colspan="6" align="center">Total registros identificados: <? echo $num_reg?><input type="hidden" name="nreg" value="<? echo $num_reg?>">
        </tr>
        <tr>
            <td colspan="6" align="center"><input type="submit" name="submit" value="submit">
    </table>
    </form>
    <strong></strong>
    </body>
</html>   
 <? //en caso de que no hubisemos iniciado session
       //tenemos que dirigir al usuario donde pueda hacerlo
      //esto es la pagina de login
    
else {
        
header ("Location:/terpor/login.php");
    }
?>
el script checkin.php seria este:
Código PHP:
<? session_start ();
include (
'db-conn.php');
//recojemos las variables del formulario
$vid $_POST["vid"];
$status=$_POST["status".$rows ["id"]];
$parking=$_POST["campa".$rows ["id"]];
$fila=$_POST["fila".$rows ["id"]];
$posicion=$_POST["posicion".$rows ["id"]];
$numreg $_POST["nreg"];

//agregamos los datos a la tabla
for ($x 1$x <= $numreg$x++) {
        
$result mysql_query("INSERT INTO c_ubicacion (vid, parking, fila, columna) VALUES ('$vid','$status', '$parking', '$fila', '$posicion'");
        }
header ("Location:/terpor/");
?>
Aparte de no agregar a la tabla c_ubicacion, cuando hay mas de 150 registros me da el sguiente error:

Request-URI Too Large

The requested URL's length exceeds the capacity limit for this server.

alguien me puede echar una mano???