Foros del Web » Programando para Internet » PHP »

Como modificar varios registros desde un formulario

Estas en el tema de Como modificar varios registros desde un formulario en el foro de PHP en Foros del Web. Cita: Iniciado por urgido último intento hahaha <? if (isset($_POST["enviar"])) { $count=count($_POST['id']); for($i=0;$i<$count;$i++){ $sql_update=mysql_query("UPDATE registros SET activo='".$_POST['activar'][$i]."' WHERE id='".$_POST['id'][$i]."'",$con) or die("Problemas en el select:".mysql_error()); } ...

  #31 (permalink)  
Antiguo 12/12/2009, 01:34
 
Fecha de Ingreso: marzo-2009
Mensajes: 74
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: Como modificar varios registros desde un formulario

Cita:
Iniciado por urgido Ver Mensaje
último intento hahaha

<?
if (isset($_POST["enviar"])) {

$count=count($_POST['id']);
for($i=0;$i<$count;$i++){
$sql_update=mysql_query("UPDATE registros SET activo='".$_POST['activar'][$i]."' WHERE id='".$_POST['id'][$i]."'",$con) or die("Problemas en el select:".mysql_error()); }
}
}


?>


<div align="center">
<center>
<table border="2" width="48%" height="37" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#800000">
<tr>
<td width="15%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">&nbsp;Id:</font></b></td>
<td width="6%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<p align="center">
<b><font face="Arial Narrow" size="2">Activo:</font></b></td>
<td width="7%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Activar:</font></b></td>
<td width="9%" height="19" bgcolor="#FFFF99" align="center" style="border: 2px outset #000080">
<b><font face="Arial Narrow" size="2">Desactivar:</font></b></td>
</tr>
<?
// Imprimiendo los resultados
while($array = mysql_fetch_array($cad)) {
$id=$array['id'];
$activ=$array['activo'];

if ( $activ == "" || $activ == "no" ) {
$activo2 = "No";}
else{
$activo2 = "Sí";}

?>
<form name="f1" method="post" action="<? echo $_SERVER['PHP_SELF'];?>">
<tr>
<td width="15%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;&nbsp; </span></td>
<td width="6%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="7%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
<td width="9%" height="6" bgcolor="#800000">
<span style="font-size: 3pt">&nbsp;</span></td>
</tr>
<tr>
<td width="15%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $id; ?>&nbsp;</font></b></td>
<td width="6%" height="27" style="border: 2px outset #000080" bgcolor="#FFFFFF">
<p align="center"><b><font size="2" face="Arial Narrow"><? echo $activo2; ?>&nbsp;</font></b></td>
<td width="7%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar[]" value="si"></td>
<td width="9%" height="27" bgcolor="#FFFFFF" style="border: 2px outset #000080">
<p align="center"><input type="radio" name="activar[]" value="no"></td>
</tr>
<tr>
<td width="37%" height="37" colspan="4">
&nbsp;</td>
</tr>
<input type="text" name="id[]" value="<? echo $id; ?>" style="display:none" />
<?
}
?>

<tr><td><input type="submit" value="Enviar" name="enviar" style="font-family: Arial Narrow; font-size: 10pt; font-weight: bold"></form></td></tr>
<?
$con=mysql_close($con);
?>

</table>
</center>
</div>
Hola de verdad, de verdad que eres un super genio , me funcionó perfecto, no tienes idea de cuanto te agradezco el interés y la ayuda que me has dado eres un

¡¡Muchisimas Gracias!!!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:15.