Foros del Web » Programando para Internet » PHP »

Problema con Undefined index

Estas en el tema de Problema con Undefined index en el foro de PHP en Foros del Web. Tengo el siguiente trozo de codigo: Código PHP: <?php include( "seguridad.php" ); ?> <!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>Sniace - Administrador</title> <link href="../../estilos.css" rel="stylesheet" type="text/css" /> <script language="javascript"> function pregunta(valor,valor1) { if(confirm("¿Esta seguro que desea borrarlo?")) document.location.href="borraip.php?id="+valor+"&i="+valor1; else ...
  #1 (permalink)  
Antiguo 17/08/2010, 04:48
 
Fecha de Ingreso: agosto-2010
Mensajes: 17
Antigüedad: 13 años, 8 meses
Puntos: 0
Problema con Undefined index

Tengo el siguiente trozo de codigo:

Código PHP:
<?php
include("seguridad.php");
?>
<!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>Sniace - Administrador</title>
<link href="../../estilos.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function pregunta(valor,valor1)
{
if(confirm("¿Esta seguro que desea borrarlo?"))
document.location.href="borraip.php?id="+valor+"&i="+valor1;
else
document.location.href="";
}
</script>
</head>
<body>
<table id="tablaprinc" align="center" width="862" height="364" border="0">
  <tr>
    <td width="95%" height="86"><div align="left">
      <table align="center" width="631" border="0">
        <tr>
          <td><img src="../../img/sniace.jpg" width="209" height="82" alt="sniace" /></td>
          <td><img src="../../img/image(2).png" alt="Inet" width="377" height="71" /></td>
        </tr>
      </table>
    </div></td>
  </tr>
  <tr>
    <td width="95%" height="43"><table width="99%" height="34" border="0">
      <tr>
    <td width="95%" height="43"><table width="99%" height="34" border="0">
      <tr>
        <td width="20%" id="menus"><a href="../Incidencias/administrarincidencias.php">Incidencias</a></td>
        <td width="20%" align="left" id="menus"><a href="../Noticias/administranoticia.php">Noticias</a></td>
        <td width="20%" id="menus"><a href="../extensiones/extensiones.php">Extensiones</a></td>
        <td width="20%" id="menus"><a href="../Numeros/numeros.php">M&oacute;viles</a></td>
        <td width="20%" align="left" id="menus"><a href="../correo/correo.php">Correo</a></td>
      </tr>
    </table>    </td>
  </tr>
    </table>    </td>
  </tr>
  <tr>
    <td><table width="99%" height="34" border="0">
      <tr>
        <td width="20%"></td>
        <td width="20%"></td>
        <td width="20%" id="menus"><a href="../ip/administrarip.php">IP</a></td>
        <td width="20%"></td>
       <td width="20%"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td width="95%" height="180">
    <p id="incidencia" >Administraci&oacute;n de Direcciones IP</p>
<table align="right" width="15%" border="0">
  <tr>
  <?php
  
if (isset($_GET["i"]))
  {
      
$var=$_GET["i"];
  }
  echo 
'
    <td id="panelc"><a href="informe.php?i='
.$var.'"><div align="center">
          <p><img src="../../img/plantillas_de_factura.png" alt="informe" width="128" height="128" border=0/>
          Tabla de Direcciones</p>
    </div></a></td>'
;
    
?>
  </tr>
</table>
<p></p>
        <p>
          <?php
//conexion a la base de datos

include("conexion1.php");
$link=Conectarse();

if (isset(
$_GET["i"]))
{
$var=$_GET["i"];
}

$var=$_GET["i"];

if(
$var==0){
$nombre="direccionesip0";
}
if(
$var==1){
$nombre="direccionesip1";
}
if(
$var==2){
$nombre="direccionesip2";
}
if(
$var==4){
$nombre="direccionesip4";
}
if(
$var==5){
$nombre="direccionesip5";
}
if(
$var==10){
$nombre="direccionesip10";
}

/******** INSERT CON PROCEDIMIENTO ALMACENADO **********/
$sql="SELECT * FROM $nombre";
$var1=1
$result mysql_query($sql,$link);


$link=Conectarse();
// $nombre procede de index.php y contiene la tabla seleccionada por el usuario en una lista desplegable.
//Es imprescindible pasarlo como variable en los enlaces de paginacion

$colorfila=0;

echo 
"<table border=1 align='center'>";
echo
"<tr align=center>";
$color"#D3DCE3"

if (
mysql_num_rows($result)> 0) {
   echo 
"<td bgcolor=".$color.'><a href="ip.php?i='.$var.'">IP</a></td>';
   echo 
"<td bgcolor=".$color.'><a href="ip.php?a=1&i='.$var.'">Nombre</a></td>';
   echo 
"<td bgcolor=".$color.">Accion</td>";
   } 
if (isset(
$_GET["a"])){
$result2 mysql_query("SELECT * FROM $nombre WHERE Nombre NOT LIKE '' ORDER BY $nombre.Nombre ASC;",$link);
}
else{
$result2 mysql_query("SELECT * FROM $nombre ORDER BY $nombre.ID ASC;",$link);
}
while (
$row2 mysql_fetch_array($result2MYSQL_NUM)) {
if (
$colorfila==0){ 
       
$color"#F5F5F5"
       
$colorfila=1
    }else{ 
       
$color="#D5D5D5"
       
$colorfila=0
    }
echo 
"<tr align=center>";
  if (
$row2[3]==1)
      {
      echo 
"<td bgcolor='".$color."'><font color=red><b>".$row2[1]."</b></font></td>";
      echo 
"<td bgcolor='".$color."'><font color=red><b>".$row2[2]."</b></font></td>";
      }
   else{
         echo 
"<td bgcolor='".$color."'>",$row2[1],"</td>";
      echo 
"<td bgcolor='".$color."'>",$row2[2],"</td>";
   }
   
      
$var=$_GET["i"];
      echo 
"<td align=center bgcolor='".$color."'",'><a href="editaip.php?id='.$row2[0].'&nom='.$row2[2].'&ip='.$row2[1].'&i='.$var.'"><img src="../../img/edit.png" width="25" height="25" border=0/></a>';
      echo 
'<a href="borraip.php?&id?id='.$row2[0].'&nom='.$row2[2].'&ip='.$row2[1].'&i='.$var.'"><img src="../../img/delete.png" alt="delete" width="25" height="25" onClick="pregunta('.$row2[0].','.$var.');" border=0/></a></td>';
      
    
echo 
"</tr>";
}
echo 
"</table>";
?>
        </p>
        <p><br />
            <br />
          </p>
      </p></td>
  </tr>
   <tr>
    <td>    
    <table align="center" width="23%" border="0">
        <tr>
          <td id="panelc"><a href="administrarip.php"><img src="../../img/volver.png" alt="volver" width="187" height="83" border="0" /></a></td>
        </tr>
      </table></td>
  </tr>
  <tr>
  <td>   
    <p align="right"><a href="../../login.php"><img src="../../img/apagar.png" alt="logout" width="30" height="30" border="0" /></a></p></td>
  </tr>
</table>
</table>
</body>
</html>
Me da el error Notice: Undefined index: i in C:\wamp\www\Administrador\IP\ip.php on line 89

Notice: Undefined index: i in C:\wamp\www\Administrador\IP\ip.php on line 156

y aunque lo miro y remiro no se me ocurre que puede ser. Acepto sugerencias
  #2 (permalink)  
Antiguo 17/08/2010, 05:27
 
Fecha de Ingreso: agosto-2010
Ubicación: Madrid
Mensajes: 53
Antigüedad: 13 años, 8 meses
Puntos: 1
Respuesta: Problema con Undefined index

Es porque estas en ejecutandolo en el local, cuando lo subas a un servidor no aparecerá, es porque hasta que no le mandes el GET no lo encuentra, si no quieres que te moleste ese error precede a la variable un @, en plan @$_GET['i'];
  #3 (permalink)  
Antiguo 17/08/2010, 06:25
Avatar de angelAparicio  
Fecha de Ingreso: julio-2009
Ubicación: Sevilla
Mensajes: 307
Antigüedad: 14 años, 9 meses
Puntos: 22
Respuesta: Problema con Undefined index

Creo que te has dejado una linea fuera del if en:

Código PHP:
if (isset($_GET["i"]))
{
$var=$_GET["i"];
}

$var=$_GET["i"]; //Supongo que esta linea sobra 
  #4 (permalink)  
Antiguo 17/08/2010, 07:02
 
Fecha de Ingreso: agosto-2010
Mensajes: 17
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: Problema con Undefined index

Ok, ya funciona perfectamente, gracias

Etiquetas: index, undefined
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:04.