Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/01/2009, 10:42
hollowmanf
 
Fecha de Ingreso: enero-2009
Mensajes: 246
Antigüedad: 15 años, 3 meses
Puntos: 1
Problema con Variable

Hola amigos del Foro, les escribo porque estoy teniendo un error en un php, soy novato en el tema y quiero ver si alguien puede ayudarme.

Tengo una base de datos asi:

CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`lastname` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=7 ;

--
-- Dumping data for table `test_mysql`
--

INSERT INTO `test_mysql` VALUES (1, 'Billly', 'Blueton', '[email protected]');
INSERT INTO `test_mysql` VALUES (2, 'Jame', 'Campbell', '[email protected]');
INSERT INTO `test_mysql` VALUES (3, 'Mark', 'Jackson', '[email protected]');
INSERT INTO `test_mysql` VALUES (4, 'Linda', 'Travor', '[email protected]');
INSERT INTO `test_mysql` VALUES (5, 'Joey', 'Ford', '[email protected]');
INSERT INTO `test_mysql` VALUES (6, 'Sidney', 'Gibson', '[email protected]');


Y luego un php que lo que deberia hacer es el Update de los registros que tengo en la base de datos, coloco el codigo de fuente del php:

<strong>Update multiple rows in mysql</strong><br>

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // 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 $tbl_name";
$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="">
<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)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>"></td>
<td align="center"><input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>"></td>
<td align="center"><input name="email[]" type="text" id="email" value="<? 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($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if($result1){
header("location:update_multiple.php");
}
mysql_close();
?>

Esto lo estoy usando en local en mi pc con elo EasyPhp, el problema surge que a la hora de ejecutar el php me tira el siguiente error:


Notice: Undefined variable: Submit in C:\Program Files\EasyPHP 2.0b1\www\update_multiple.php on line 55

Notice: Undefined variable: result1 in C:\Program Files\EasyPHP 2.0b1\www\update_multiple.php on line 63

Y no logro deducir cual puede ser el problema, les pido si alguien puede darme una mano, desde ya muchas gracias por todo.

Saludos Hollowmanf