ERROR:
Código PHP:
Notice: Undefined index: tablas in c:program fileseasyphpwwwscriptsdelete.php on line 55
MySQL dice: You have an error in your SQL syntax near 'WHERE ID IN(40,41,42,39,38,37))' at line 1
Código PHP:
<?php
//Definimos la Coneccion
$oCon = mysql_connect ("localhost","plastico","362514") or die (mysql_error());
//arreglo de tablas
$tbls[0]="tabla01";
$tbls[1]="tabla02";
$tbls[2]="tabla03";
//arreglos nombre de tablas para el combo box
$txt[0]="Tabla 01";
$txt[1]="Tabla 02";
$txt[2]="Tabla 03";
//formulario y tabla?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>" enctype="multipart/form-data">
<table name="formulario" width="770" border="1" align="center">
<tr>
<td>Eliminar Datos desde:</td>
<td> <?php $tablas= "<select name=\"tablas\">"; echo $tablas;?>
<?php for ($i = 0; $i <= 2; $i++){
echo "<option value=\"".$tbls[$i]."\">".$txt[$i]."</option>";
}?>
</select> <input type="Submit" name="Submit" value="Enviar"></td>
</tr>
</table></form>
<?php
//Query a la base de datos
if(isset($_POST['Submit']))
{
mysql_select_db("prueba");
$result = mysql_query("SELECT * FROM ".$_POST['tablas']."") or die("MySQL dice: ".mysql_error());
//SACAMOS A RELUCIR LAS TABLAS
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\" enctype=\"multipart/form-data\">
<table name=\"tabla\" width=\"770\" border=\"1\" align=\"center\">
<tr>
<td>Nombre</td><td>Subtitulos</td><td>Eliminar</td>";
while($row=mysql_fetch_array($result))
{
echo "<tr><td>".$row['nombre']."</td>
<td>".$row['subtitulo']."</td><td><input type=\"checkbox\" name=\"eliminar[]\" value=\"".$row['ID']."\"></td>";
}
echo "</tr><tr><td colspan=\"3\" bgcolor=\"gray\" align=\"right\"><input type=\"Submit\" name=\"Borrar\" value=\"Borrar\"></tr></td>
</table></form>";
}
//ELIMINAMOS ID DE LA RESPECTIVA TABLA
if(isset($_POST['Borrar']))
{
$array =implode(',',$_POST['eliminar']);
mysql_select_db("prueba");
mysql_query("DELETE FROM ".$_POST['tablas']. "WHERE ID IN(".$array."))",$oCon) or die("MySQL dice: ".mysql_error());
}
Saludos