Ver Mensaje Individual
  #4 (permalink)  
Antiguo 07/03/2009, 09:32
Avatar de Nefertiter
Nefertiter
 
Fecha de Ingreso: enero-2003
Ubicación: Rosario
Mensajes: 1.316
Antigüedad: 21 años, 4 meses
Puntos: 9
Respuesta: actualizacion multiple

Mira la diferencias..

Código PHP:
<?php 
$host
="localhost"// Host name  
$username=""// Mysql username  
$password=""// Mysql password  
$db_name=""// Database name  
$tbl_name="test_mysql"// Table name  

// Connect to server and select databse. 
mysql_connect($host$username$password)or die("cannot connect");  
mysql_select_db($db_name)or die("cannot select DB"); 

$sql="SELECT * FROM test_mysql"
$result=mysql_query($sql); 

// Count table rows  
$count=mysql_num_rows($result); 
?> 
<table width="500" border="0" cellspacing="1" cellpadding="0"> 
<form name="form1" method="post" action="<?=$_SERVER['REQUEST_URI']?>"> 
<tr>  
<td> 
<table width="500" border="0" cellspacing="1" cellpadding="0"> 


<tr> 
<td align="center"><strong>Id</strong></td> 
<td align="center"><strong>Name</strong></td> 
<td align="center"><strong>Lastname</strong></td> 
<td align="center"><strong>Email</strong></td> 
</tr> 
<?php 
while($rows=mysql_fetch_array($result)){ 
//no deberias poner tu ide en un input tambien??
?> 
<tr> 
<td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td> 
<td align="center"><input name="name[]" type="text" id="name" value="<?php echo $rows['name']; ?>"></td> 
<td align="center"><input name="lastname[]" type="text" id="lastname" value="<?php echo $rows['lastname']; ?>"></td> 
<td align="center"><input name="email[]" type="text" id="email" value="<?php echo $rows['email']; ?>"></td> 
</tr> 
<?php 

?> 
<tr> 
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> 
</tr> 
</table> 
</td> 
</tr> 
</form> 
</table> 
<?php 
// Check if button name "Submit" is active, do this  
if(isset($_POST['Submit'])){ 
for(
$i=0;$i<$count;$i++){ 
$sql1="UPDATE test_mysql SET name='".$_POST['name'][$i]."', lastname='".$_POST['lastname'][$i]."', email='".$_POST['email'][$i]."' WHERE id='".$_POST['id'][$i]."'"
$result1=mysql_query($sql1) or die(mysql_error().$sql1); 



if(
$result1){ 
header("location:update_multiple.php"); 

mysql_close(); 
?>