Foros del Web » Programando para Internet » PHP »

Relaciones de tablas

Estas en el tema de Relaciones de tablas en el foro de PHP en Foros del Web. Hola, tengo un problema. No me borra el registro de generos, que esta relacionado con el de musica, solo me elimina el de musica, ademas ...
  #1 (permalink)  
Antiguo 22/10/2012, 13:04
 
Fecha de Ingreso: octubre-2012
Ubicación: Caracas, Venezuela
Mensajes: 31
Antigüedad: 11 años, 7 meses
Puntos: 0
Relaciones de tablas

Hola, tengo un problema.
No me borra el registro de generos, que esta relacionado con el de musica, solo me elimina el de musica, ademas me da un error.

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 
ejecutar2 ($sql2,$idc){
    return 
mysql_query($sql2,$idc);
    }

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


function 
totalRegistros ($res1){
    return 
mysql_num_rows ($res1);
    }
    function 
totalRegistros2 ($res2){
    return 
mysql_num_rows ($res2);
    }
        
function 
getRegistro ($res1){
    return 
mysql_fetch_array ($res1);
    }
function 
getRegistro2 ($res2){
    return 
mysql_fetch_array ($res2);
    }



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


?>
Código PHP:
<?php 

$id 
$_GET['id'];  
 
          
$idg = isset($_POST["idg"])? $_POST["idg"]: '';  

require (
"funciones2.php");

$idc conectar();




$sql2 "SELECT * FROM generos WHERE idg=$idg";
$res2 ejecutar2($sql2,$idc);
$fila getRegistro2 ($res2);

$sql "SELECT * FROM musica WHERE id=$id";
$res1 ejecutar($sql,$idc);
$fila getRegistro ($res1);



$sql2 "DELETE FROM generos WHERE idg=$idg"
$res2 ejecutar2($sql2$idc);

$sql "DELETE FROM musica WHERE id=$id";
$res1 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 de rock</title>
<link href="formato1.css" rel="stylesheet" type="text/css" />
</head>
<body>


   <?php 
if ($res1)
    echo 
"ELIMINACIÓN EXITOSA";
 elseif (
$res2)
    echo 
"ELIMINACIÓN EXITOSA";
    
else    
echo 
"ERROR";



?>

 
<br/>
<br/>

</body>
</html>
<?php 
cerrar 
($idc);
?>

( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Edward-Relaciones\funciones2.php on line 33
Call Stack
# Time Memory Function Location
1 0.0004 144072 {main}( ) ..\eliminar.php:0
2 0.0022 157440 getRegistro2( ) ..\eliminar.php:17
3 0.0022 157488 mysql_fetch_array ( ) ..\funciones2.php:33
ELIMINACIÓN EXITOSA

Por favor necesito su ayuda, gracias, saludos y hablamos.
  #2 (permalink)  
Antiguo 22/10/2012, 14:48
Avatar de rodrigo791  
Fecha de Ingreso: noviembre-2009
Ubicación: Uruguay
Mensajes: 1.339
Antigüedad: 14 años, 5 meses
Puntos: 168
Respuesta: Relaciones de tablas

No crees 2 temas relacionados con lo mismo, te pueden sancionar por eso.

Código PHP:
Ver original
  1. $idg = isset($_POST["idg"])? $_POST["idg"]: '';

y vos estás seguro de que te está llegando algo en idg?
hace var_dump($idg); luego de esa línea, a ver si tenes valores dentro.

Creo que debe venir por ahí el problema, ya que errores de SQL no tenes.
Si el valor de $idg llegara a ser vacío entonces es un problema, ya que no te estaría devolviendo datos tu consulta SQL la cual se almacena en $res2.
  #3 (permalink)  
Antiguo 22/10/2012, 15:11
 
Fecha de Ingreso: octubre-2012
Ubicación: Caracas, Venezuela
Mensajes: 31
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: Relaciones de tablas

Amigo, me sale esto:
string '' (length=0)
y luego mi error

SCREAM: Error suppression ignored for
( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Edward-Relaciones\funciones2.php on line 33
Call Stack
# Time Memory Function Location
1 0.0006 144664 {main}( ) ..\eliminar.php:0
2 0.0026 158040 getRegistro2( ) ..\eliminar.php:17
3 0.0026 158088 mysql_fetch_array ( ) ..\funciones2.php:33
ELIMINACIÓN EXITOSA
  #4 (permalink)  
Antiguo 22/10/2012, 15:15
 
Fecha de Ingreso: octubre-2012
Ubicación: Caracas, Venezuela
Mensajes: 31
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: Relaciones de tablas

Sabes otra cosa, si quito esta linea, no da error, pero no me elimina el registro de generos.
Código PHP:
$sql2 "SELECT * FROM generos WHERE idg=$idg";
$res2 ejecutar2($sql2,$idc);
$fila2 getRegistro2 ($res2);

$sql "SELECT * FROM musica WHERE id=$id";
$res1 ejecutar($sql,$idc);
$fila getRegistro ($res1);



$sql2 "DELETE FROM generos WHERE idg=$idg"
$res2 ejecutar2($sql2$idc);

$sql "DELETE FROM musica WHERE id=$id";
$res1 ejecutar($sql,$idc); 
Esta linea si la elimino, $fila2=getRegistro2($res2); no me aparece error, pero no elimina.
  #5 (permalink)  
Antiguo 22/10/2012, 15:34
 
Fecha de Ingreso: octubre-2012
Ubicación: Caracas, Venezuela
Mensajes: 31
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: Relaciones de tablas

Sera que el problema esta aqui, pero yo no lo veo, ayuda por favor.

Código PHP:
<?php 

require ("funciones2.php");

$idc conectar();

$sql="SELECT * FROM musica m, generos g  WHERE m.idg = g.idg";
//$sql2="SELECT * FROM musica m, generos g  WHERE m.idg = g.idg";

$res1 ejecutar ($sql,$idc);
$res2 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 de rock</title>
<link href="formato1.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form action="agregar.html" method="post" id="agregar" name="agregar" >
<form action="buscar.html" method="post" id="buscar" name="buscar" >

<table width="1019" height="79" align="center"  class="color1" id="Listar">
<caption>
<br />
<br />
LISTADO DE REGISTRO DE CD DE MÚSICA<br />
<br /><br />
<br /><input type="submit"  formaction="agregar.html"  name="agregar" id="agregar" value="Agregar" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit"  formaction="buscar.html" name="buscar" id="buscar" value="Buscar" /><br />
<br /></caption>
  <tr>
    <th width="58" align="center">Id</th>
    <th width="207" align="center">Album</th>
    <th width="172" align="center">Artista</th>
    <th width="109" align="center">Canciones</th>
   
    <th width="275" align="center">Generos</th>
    <th width="58" align="center">Año</th>
    <th width="80" align="center">Imagen</th> 
   
  </tr>


 
  <?php 
  $total 
totalRegistros($res1);
   
  for (
$i=0$i<$total$i++) {
      
$fila getRegistro($res1);
      
  
?>
  
  
  
   <tr>
   <td align="center"><?php echo $fila['id']; ?></td>
    <td align="center"><a href="modificar.php?id=<?php echo $fila['id']; ?>"><?php echo $fila['album']; ?></a></td>
    
    <td align="center"><?php echo $fila['artista']; ?></td>
   <td align="center"><?php echo $fila['canciones']; ?></td>
  
  
    <?php 

   $total2 
totalRegistros2($res2);
  for (
$i=0$i<$total2$i++) {
      
       
$fila2 getRegistro2($res2);
  
?>
   <td align="center"><?php echo $fila2['genero1']; ?><?php echo " " ?>
    <?php echo $fila2['genero2']; ?><?php echo " " ?>
    <?php echo $fila2['genero3']; ?><?php echo " " ?>
    <?php echo $fila2['genero4']; ?><?php echo " " ?>
    <?php echo $fila2['genero5']; ?><?php echo " " ?>
    <?php echo $fila2['genero6']; ?><?php echo " " ?>
    <?php echo $fila2['genero7']; ?><?php echo " " ?>
    <?php echo $fila2['genero8']; ?><?php echo " " ?>
   
   </td>
     <?php ?>
   <td align="center"><?php echo $fila['ano']; ?></td>
   
   
   
   <td width="80"><?php echo "<img src='Imagenes/" .$fila['imagen']. "' height='80'/>"?> </td>
<td width="26" align="center" > <a href="eliminar.php?id=<?php echo $fila['id']; ?>"><img src="imagenes/eliminar.png" width="16" height="16" border = "0"/></a> </td> 
  <?php ?>
 
 </tr>
</table>
</body>
</html>
<?php 
cerrar 
($idc);
?>
Este archivo es listar.php

Etiquetas: html, mysql, registro, relaciones, sql, tablas
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 02:54.