Foros del Web » Programando para Internet » PHP »

Problema de undefined index.

Estas en el tema de Problema de undefined index. en el foro de PHP en Foros del Web. Hola a todos, espero que esten bien. Bueno, tengo un nuevo problema, en una aplicacion, le explico: Base de datos. Tabla musica2. Campos: id, album, ...
  #1 (permalink)  
Antiguo 18/10/2012, 07:12
 
Fecha de Ingreso: octubre-2012
Ubicación: Caracas, Venezuela
Mensajes: 31
Antigüedad: 11 años, 6 meses
Puntos: 0
Problema de undefined index.

Hola a todos, espero que esten bien.
Bueno, tengo un nuevo problema, en una aplicacion, le explico:
Base de datos.
Tabla musica2.
Campos: id, album, artista, canciones, ano e imagen.
Tabla: generos.
Campos: id_g, id, genero1, genero2, genero3.
Código PHP:
<?php 

$id 
$_GET['id'];


require (
"funciones4.php");
$idc conectar();
$sql="SELECT * FROM musica2 m, generos g WHERE m.id = g.id";
if(!
mysql_query($sql)) echo mysql_error();
$sql "select *from musica2 where id=$id";

$res ejecutar($sql,$idc);
$fila getRegistro ($res);
$sql="DELETE generos FROM generos, musica2 WHERE generos.id = musica2.id";
if(!
mysql_query($sql)) echo mysql_error();

$sql "delete from musica2 where id=$id";


$res ejecutar($sql,$idc);

?>
<!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>Sistema</title>
<link href="estilo_eliminar.css" rel="stylesheet" type="text/css" />
</head>
<body>


   <?php 
if ($res)
    echo 
"ELIMINACIÓN EXITOSA";
else
    echo 
"ERROR";
?>

 
<br/>
<br/>
<table width="330" border="10" >
 
  <tr>
    <td width="100" align="center">Álbum:</td>
    <td width="196" align="center"><?php echo $fila['album'];?></td>
  </tr>
  <tr>
    <td align="center">Artista:</td>
    <td align="center"><?php echo $fila['artista'];?></td>
  </tr>
  <tr>
    <td align="center">Canciones:</td>
    <td align="center"><?php echo $fila['canciones'];?></td>
  </tr>
  <tr>
    <td align="center">Géneros:</td>
    <td align="center"><?php echo $fila['genero1'];?><?php echo " " ?>

    <?php echo $fila['genero2'];?><?php echo " " ?>
   
    <?php echo $fila['genero3'];?><?php echo " " ?>
  
   
    
    
    </td>
  </tr>
  <tr>
    <td align="center">Año:</td>
    <td align="center"><?php echo $fila['ano'];?></td>
  </tr>  
  <tr>  
    <td align="center">Imagen:</td>
    <td align="center"><?php echo $fila['imagen'];?></td> 
  </tr>
</table>
</body>
</html>
<?php 
cerrar 
($idc);
?>
El problema es que me salen estos errores y no se como resolverlo, intento e intento y nada.

SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: genero1 in C:\wamp\www\Sistema_Edward-Bukowski\eliminar999.php on line 59

SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: genero2 in C:\wamp\www\Sistema_Edward-Bukowski\eliminar999.php on line 61

SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: genero3 in C:\wamp\www\Sistema_Edward-Bukowski\eliminar999.php on line 63

Espero sus respuestas, por favor ayudenme.
Gracias por todo, saludos y hablamos.
Hasta luego.
  #2 (permalink)  
Antiguo 18/10/2012, 08:40
Avatar de mauled  
Fecha de Ingreso: marzo-2005
Ubicación: Cd. de México.
Mensajes: 3.001
Antigüedad: 19 años, 1 mes
Puntos: 33
Respuesta: Problema de undefined index.

Lo que pasa, por lo que observo, es un tema del orden en que vas ejecutando tu query pues redefines el valor de la variable $sql


Código PHP:
$sql="SELECT * FROM musica2 m, generos g WHERE m.id = g.id";
if(!
mysql_query($sql)) echo mysql_error();
$sql "select *from musica2 where id=$id"//Aqui ya se perdio la referencia a Generos

$res ejecutar($sql,$idc);
$fila getRegistro ($res);// $fila solo tiene los valores de la tabla musica2 
Revisa bien el uso de tu variable $sql. O bien define otra variable para obtener los valores de generos.

Saludos.
  #3 (permalink)  
Antiguo 18/10/2012, 13:26
 
Fecha de Ingreso: octubre-2012
Ubicación: Caracas, Venezuela
Mensajes: 31
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Problema de undefined index.

Entiendo lo que me dices, pero podrias decirme, como deberia de hacerlo, para que me funcione, porque intento y nada.
  #4 (permalink)  
Antiguo 18/10/2012, 15:06
 
Fecha de Ingreso: octubre-2012
Ubicación: Caracas, Venezuela
Mensajes: 31
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Problema de undefined index.

Si hago esto, cambiar mis variables sql de orden, me da este error.

Código PHP:
<?php 



$id 
$_GET['id'];


 require (
"funciones4.php");

$idc conectar();


$sql="SELECT * FROM musica2 m, generos g WHERE m.id = g.id";
if(!
mysql_query($sql)) echo mysql_error(); 

$sql="DELETE generos FROM generos, musica2 WHERE generos.id = musica2.id";


$res ejecutar($sql,$idc);
$fila getRegistro ($res);




$sql "select *from musica2 where id=$id";


if(!
mysql_query($sql)) echo mysql_error(); 

$sql "delete from musica2 where id=$id";


$res ejecutar($sql,$idc);












?>
<!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>Sistema</title>
<link href="estilo_eliminar.css" rel="stylesheet" type="text/css" />
</head>
<body>


   <?php 
if ($res)
    echo 
"ELIMINACIÓN EXITOSA";
else
    echo 
"ERROR";
?>

 
<br/>
<br/>
<table width="330" border="10" >
 
  <tr>
    <td width="113" align="center">Álbum:</td>
    <td width="183" align="center"><?php echo $fila['album'];?></td>
  </tr>
  <tr>
    <td align="center">Artista:</td>
    <td align="center"><?php echo $fila['artista'];?></td>
  </tr>
  <tr>
    <td align="center">Canciones:</td>
    <td align="center"><?php echo $fila['canciones'];?></td>
  </tr>
  <tr>
    <td align="center">Géneros:</td>
    <td align="center"><?php echo $fila['genero1'];?><?php echo " " ?>

    <?php echo $fila['genero2'];?><?php echo " " ?>
   
    <?php echo $fila['genero3'];?><?php echo " " ?>
  
    
    
    
    </td>
  </tr>
  <tr>
    <td align="center">Año:</td>
    <td align="center"><?php echo $fila['ano'];?></td>
  </tr>  
  <tr>  
    <td align="center">Imagen:</td>
    <td align="center"><?php echo $fila['imagen'];?></td> 
  </tr>
</table>
</body>
</html>
<?php 
cerrar 
($idc);
?>

Error.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Sistema_Edward-Bukowski\funciones4.php on line 22

Código PHP:
<?php
function conectar() {
    
$idc mysql_connect ("localhost""root""");
    if (!
$idc)
        die (
"Error en la conexion al MYSQL");
    if (!
mysql_select_db ("bd_prueba3"$idc))
        die(
"Error en la seleccion de la BD");
        
mysql_query ("SET NAMES 'utf8'");
        return 
$idc;
    
    }

function 
ejecutar ($sql,$idc){
    return 
mysql_query($sql,$idc);
    }

function 
totalRegistros ($res){
    return 
mysql_num_rows ($res);
    }
    
function 
getRegistro ($res){
    return 
mysql_fetch_array ($res);
    }



function 
cerrar ($idc){
    
mysql_close($idc);
    }


?>
Por favor como puedo solucionar este problema.
Saludos.

Etiquetas: html, mysql, registro, sql, tabla, 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 11:10.