VeneHosting.com :: Tu Hosting en Venezuela

Autor Tema: Borrar varios registros con checkboxes (Casillas de verificación).  (Leído 643 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Adrian_PHP

  • Novato
  • *
  • Mensajes: 12
  • Puntuación: 0
  • Sexo: Masculino
    • Ver Perfil
    • BlogPHP con Dreamweaver | Sistema de Weblog gratuito
Está basado en la función de eliminar registros de las librerías de PHP de Dreamweaver 8.

Código: [Seleccionar]
<?php
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "&#39;" $theValue "&#39;" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "&#39;" doubleval($theValue) . "&#39;" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "&#39;" $theValue "&#39;" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}

$editFormAction $_SERVER[&#39;PHP_SELF&#39;];
if (isset($_SERVER[&#39;QUERY_STRING&#39;])) {
  
$editFormAction .= "?" htmlentities($_SERVER[&#39;QUERY_STRING&#39;]);
}

if ((isset(
$_POST[&#39;id&#39;])) && ($_POST[&#39;id&#39;] != "")) {
  
$aLista $_POST[&#39;id&#39;];
  
$deleteSQL sprintf("DELETE FROM mensajes WHERE id IN (".implode(&#39;,&#39;,$aLista).")",
                       
GetSQLValueString($_POST[&#39;id&#39;], "int"));

  
mysql_select_db($database_conexionSQL$conexionSQL);
  
$Result1 mysql_query($deleteSQL$conexionSQL) or die(mysql_error());

  
$deleteGoTo "../../admin/mensajes/";
  if (isset(
$_SERVER[&#39;QUERY_STRING&#39;])) {
    
$deleteGoTo .= (strpos($deleteGoTo, &#39;?&#39;)) ? "&" : "?";
    
$deleteGoTo .= $_SERVER[&#39;QUERY_STRING&#39;];
  
}
  
header(sprintf("Location: %s"$deleteGoTo));
}

// Aquí debe ir la consulta $row_registro que pongo de ejemplo en el formulario
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php if ($totalRows_registro 0) { // Show if recordset not empty ?>
<form id="borraRegistro" name="borraRegistro" method="POST" action="index.php">
<input type="submit" value="Borrar registros marcados" />
<?php do { ?>
<input type="checkbox" name="id[]" value="<?php echo $row_registro[&#39;id&#39;] ?>" title="Selecciona para luego Eliminar" />
<?php echo htmlentities($row_registro[&#39;titulo&#39;]); ?>
<?php } while ($row_bandeja_entrada mysql_fetch_assoc($bandeja_entrada)); ?>
</form>
<?php // Show if recordset not empty ?>
</body>
</html>
« Última Modificación: 30 de enero de 2010, 10:15:11 pm por Adrian_PHP »
Te hablo en PHP y en español.

PHP de Venezuela


 

PHP de Venezuela on Facebook