Ver Mensaje Individual
  #7 (permalink)  
Antiguo 28/12/2010, 11:12
Carlos29_2
 
Fecha de Ingreso: marzo-2010
Mensajes: 10
Antigüedad: 14 años, 1 mes
Puntos: 0
Respuesta: Problema con Delete

Lo he hecho y nada:

Vuelvo a copiar el código y luego el resultado de los var_dump

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="foodtime"; // Database name
$tbl_name="sociedad"; // 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=mysql_num_rows($result);
echo $count;


?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Nombre</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Direccion</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Tlfno</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>CIF</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Tlfno2</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Fax</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){

var_dump($rows['id_Soc']);
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id_Soc']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['id_Soc']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['nombre']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['direccion']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['tlf']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['cif']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['tlf2']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['email']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['fax']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>

<?php
// Check if delete button active, start this
if (isset($_POST['delete'])){
//print_r($_POST);
//exit
for($i=0;$i<$count;$i++){
$del_id = $checkbox[0];
var_dump($del_id);
$sql = "DELETE FROM $sociedad WHERE id_Soc='$del_id'";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=eliminar_sociedad.php\">";
}else{
echo mysql_error();

}
}
mysql_close();
?>
</table>
</form>
</td>
</table>



1 Delete multiple rows in mysql
# Id Nombre Direccion Tlfno CIF Tlfno2 Email Fax
string(1) "2" 2 Kiko Las Nieves 923222222 A123456 [email protected]

NULL You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id_Soc=''' at line 1

Qué veís?. Por lo que veo, antes tenía dos registros, y borré uno de forma manual y me dá que lo sigue teniendo en cuenta, pero no sé. Podéis ayudar?. Gracias