Foros del Web » Programando para Internet » PHP »

Borrar registro: AYUDA!!!!

Estas en el tema de Borrar registro: AYUDA!!!! en el foro de PHP en Foros del Web. Saludos, tengo un problema.. tengo un sistema de registro en base de datos que lo uso como una especia de sistema de noticias pero cuando ...
  #1 (permalink)  
Antiguo 21/09/2007, 09:51
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 19 años, 2 meses
Puntos: 28
Borrar registro: AYUDA!!!!

Saludos, tengo un problema.. tengo un sistema de registro en base de datos que lo uso como una especia de sistema de noticias pero cuando entro en el panel de control y le digo eliminar me envia a la pagina q contiene el registro para eliminar mas no elimina ni me devuelve al panel de control.. alguien podria decirme en q estoy fallando???

cpnews.php
Código PHP:
<?php
mb_http_input
("utf-8");
mb_http_output("utf-8");
?>
<?php 
require('../Connections/noticias.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

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

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

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL = sprintf("INSERT INTO noticias (id, fecha, noticia) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['fecha'], "date"),
                       
GetSQLValueString($_POST['noticia'], "text"));

  
mysql_select_db($database_noticias, $noticias);
  
$Result1 = mysql_query($insertSQL, $noticias) or die(mysql_error());

  
$insertGoTo = "../news.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s", $insertGoTo));
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset(
$_GET['pageNum_Recordset1'])) {
  
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_noticias, $noticias);
$query_Recordset1 = "SELECT * FROM noticias ORDER BY id ASC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $noticias) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset(
$_GET['totalRows_Recordset1'])) {
  
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  
$all_Recordset1 = mysql_query($query_Recordset1);
  
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

mysql_select_db($database_noticias, $noticias);
$query_Recordset1 = "SELECT * FROM noticias ORDER BY id ASC LIMIT 10"; 
$Recordset1 = mysql_query($query_Recordset1, $noticias) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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">

// ----------------
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td align="right" nowrap="nowrap" class="verdana_once">Fecha:</td>
      <td class="verdana10"><input name="fecha" type="text" id="fecha" onblur="MM_validateForm('fecha','','R');return document.MM_returnValue" value="" size="33" /></td>
    </tr>
    <tr valign="baseline">
      <td align="right" valign="top" nowrap="nowrap" class="verdana_once">Noticia:</td>
      <td class="verdana10"><textarea name="noticia" cols="20" rows="5" id="noticia" onblur="MM_validateForm('noticia','','R');return document.MM_returnValue"></textarea>
      </td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap" class="verdana10">&nbsp;</td>
      <td class="verdana10"><input type="submit" value="Insertar Noticia" /></td>
    </tr>
  </table>
  <input type="hidden" name="id" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
<table width="100%" border="0" cellspacing="4" cellpadding="0">
  <tr>
    <td width="4%" class="titulos"><strong>ID</strong></td>
    <td width="16%" class="titulos"><strong>Fecha</strong></td>
    <td width="61%" class="titulos"><strong>Noticia</strong></td>
    <td width="19%">&nbsp;</td>
  </tr>
</table>
<?php do { ?>
  <table width="100%" border="0" cellpadding="0" cellspacing="4">
    <tr>
      <td width="4%" class="verdana10"><?php echo "$row_Recordset1[id]"; ?></td>
      <td width="16%" class="verdana10"><?php echo "$row_Recordset1[fecha]"; ?></td>
      <td width="61%" class="verdana10"><?php echo "$row_Recordset1[noticia]"; ?></td>
      <td width="19%" class="verdana10"><a href="elimnot.php?ID=<?php echo $row_Recordset1['id']; ?>&Archivo=<?php echo $row_Recordset1['Archivo']; ?>" class="verdana10">Eliminar</a> / Modificar</td>
    </tr>
      </table>
  <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
elimnot.php
Código PHP:
<?php require('../Connections/noticias.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

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

if ((isset(
$_GET['id'])) && ($_GET['id'] != "")) {
  
$deleteSQL = sprintf("DELETE FROM noticias WHERE id=%s",
                       
GetSQLValueString($_GET['id'], "int"));

  
mysql_select_db($database_noticias, $noticias);
  
$Result1 = mysql_query($deleteSQL, $noticias) or die(mysql_error());

  
$deleteGoTo = "/cpanel/cpnews.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    
$deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s", $deleteGoTo));
}

mysql_select_db($database_noticias, $noticias);
$query_Recordset1 = "SELECT * FROM noticias";
$Recordset1 = mysql_query($query_Recordset1, $noticias) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
  #2 (permalink)  
Antiguo 22/09/2007, 08:44
 
Fecha de Ingreso: septiembre-2007
Mensajes: 52
Antigüedad: 19 años, 1 mes
Puntos: 2
Re: Borrar registro: AYUDA!!!!

Es un poco difícil saber con seguridad si el problema es una combinación de cosas, pero inicialmente me parece que un detalle que habría que corregir es que hacia el final de cpnews.php creas el enlace hacia elimnot.php definiendo el parámetro 'ID', y el código en elimnot.php usa $_GET['id']. Así que te sugiero que empieces ajustando esta línea:

Código PHP:
<td width="19%" class="verdana10"><a href="elimnot.php?ID=<?php echo $row_Recordset1['id']; ?>&Archivo=<?php echo $row_Recordset1['Archivo']; ?>" class="verdana10">Eliminar</a> / Modificar</td>
Para que el parámetro sea 'id' y no 'ID':
Código PHP:
<td width="19%" class="verdana10"><a href="elimnot.php?id=<?php echo $row_Recordset1['id']; ?>&Archivo=<?php echo $row_Recordset1['Archivo']; ?>" class="verdana10">Eliminar</a> / Modificar</td>
Hay otras cosas un poco extrañas, como que defines el parámetro 'Archivo', pero parece que no se usa en elminot.php ¿tal vez quieres usarlo para borrar más registros de la base de datos? Bueno, al menos espero que tengas un comienzo para seguir con tu depuración :).
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:24.