Ver Mensaje Individual
  #11 (permalink)  
Antiguo 10/06/2010, 22:09
L4NS
 
Fecha de Ingreso: mayo-2010
Mensajes: 99
Antigüedad: 14 años
Puntos: 1
Pregunta Ayuda para mostrar el username del usuario q Comente 1 Foto

amigos bueno ya el titulo lo dice todo necesito mostrar el nombre del usuario que realize un comentario en mi pagina web e intentado varias cositas pero no me ha funcionado, e googleado y todo y pues sin mas nada que intentar aki les dejo los codigos para que me ayuden el sistema de comentarios va perfecto esto es lo unico q falta. (OJO YA LAS TABLAS ESTAN RELACIONADAS USUARIO Y FOTO CON COMENTARIOS TODO VA PERFECTO EL PROBLEMA ES EN EL SCRIPT PHP)

Donde muestro los comentarios y las fotos! pero no aparece el username :(!

Código PHP:
<?php
session_start
();
?>

<?php

require_once 'PHPPaging.lib.php';

$paging = new PHPPaging


   
// Abrimos la conexión al servidor MySQL
$link mysql_connect('localhost''root''1234');
mysql_select_db('xtremebook'$link);


// Instanciamos, indicando el recurso de conexión
$paging = new PHPPaging($link);


$q "SELECT * FROM fotos ORDER BY id DESC";

// Y se usa la función agregarConsulta() (Ver documentación)
$paging->agregarConsulta($q);  

$paging->ejecutar();
?>

<?php

//Formulario
echo '<form action="Ecomentario.php" method="post">';


?>

<!--Tabla de  formulario comentarios -->

<table width="300" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
    <tr>
      <td bgcolor="#33CCFF"colspan="2"><div align="center" class="style30 style44"><b>Comentarios</b></div></td>
    </tr>
    <tr>
      <td bgcolor="#D8EFFA" width="71">
<?php

      
// incluimos en archivo para mostrar el nombre de usuario.
        
include('login.php');
        
echo 
"<b><font color='#3399FF'>".$_SESSION['MM_Username'];
?>

</b>dice:</td>
<center>
<?php
        
//Una cadena conteniendo el codigo HTML de la barra de 
//navagación es generada y guardada en la variable $links.
$links $paging->fetchNavegacion();

echo 
$links;
?>
<br />
<br />
</center>
<?php

while($datos $paging->fetchResultado()) { 

    
// En cada ciclo, la variable $datos se convierte en un arreglo
    // que contiene los datos de la fila que corresponde
    
    
echo "<img src =\"ver.php?ID=".$datos['ID']."\"width='500' height='500'><br>";
    echo 
"Nombre:" $datos['NOMBRE'] . "<br />";
    echo 
"Apellidos:" $datos['TIPO'] . "<br />";
    echo 
"País:" $datos['PESO'] . "<br />";
    echo 
"<br />";
    
$foto_id $datos['ID'];
    
?>
    
    <!-- Seguimos con la tabla del comentario en HTML -->
  
    <p>
    <td bgcolor="#D8EFFA" width="161"><span class="style29">
    <label></label>
      <textarea name="COMENTARIO[<?php echo $datos['ID']; ?>]"></textarea>
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#D8EFFA" colspan="2"><b>
       <div align="right">
          
      <?php
      
// boton Comentar
}
echo 
'<input style="background-color:#33CCFF; font:bold;  "type="submit" name="Submit" value="Comentar" />';
echo 
'</form>';

//Cerramos el Formulario
?> 
 </div>
      </b></td>
    </tr>
  </table>
  
      <!-- Se Cierra la tabla e inicia la tabla para mostrar los comentarios hechos-->
      
    </p>
    <p>&nbsp;</p>
    <table align="center" bgcolor="#D8EFFA" width="300" border="0" cellspacing="5">
      <tr>
        <th scope="row"><div align="left">
          <?php
          
          
//conectamos la base de datos
    
mysql_connect("localhost","root","pop100594") or die ("no se ha podido conectar a la BD");

    
mysql_select_db("xtremebook") or die ("no se ha podido seleccionar la BD");

//seleccionamos y filtramos el id de la foto

    
$sql "SELECT ID,COMENTARIO,FECHA,HORA,fotos_ID FROM comentarios WHERE fotos_ID = '$foto_id' " ;
    
$consulta mysql_query($sql) or die ("No se pudo ejecutar la consulta");
 
    While (
$registro=mysql_fetch_array($consulta)){
        echo 
" <br><br> Comentario: ".$registro['COMENTARIO']."<BR>hecho el:<br>".$registro['FECHA']."<BR> a las ".$registro['HORA'];
    }

?>

        </div></th>
      </tr>
      <tr>
        <th scope="row"><div align="left"> </div></th>
      </tr>
</table>
<!-- Se cierra la tabla !>

el enviar de los comentarios con el id de la foto pero sin el id de el usuario ya que no se como hacerlo :

Código PHP:
<?php
/*
                                ________________________________________________________________________
                                |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
                                |:::PROGRAMACION DEL SISTEMA INSERTAR DATOS EN BD  POR ENMANUEL DURAN:::|  
                                |:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
                                -------------------------------------------------------------------------
*/
    // Primero comprobamos que ningún campo esté vacío y que todos los campos existan.
    
$fecha=date("j-n-Y");
    
$hora=date("h:i:s");
    if(isset(
$_POST['COMENTARIO']) && !empty($_POST['COMENTARIO'])) {


        
// Si entramos es que todo se ha realizado correctamente

        
$link mysql_connect("localhost","root","1234");
        
mysql_select_db("xtremebook",$link);

       
        
//Lo definimos como array por las dudas que venga vacio y nos pinche el foreach
$COMENTARIO = array();
//Tomamos todos los valores del campo textarea anterior.
$COMENTARIO $_POST["COMENTARIO"];

        
//Por cada elemento del array, lo descompongo en Indice => Valor. Donde Indice es el ID de la foto y el Valor es lo que escribieron en el textarea.
foreach($COMENTARIO as $fotos_ID => $COMENTARIO){
    
mysql_query("insert into comentarios (fotos_ID,COMENTARIO,FECHA,HORA) values ('$fotos_ID','$COMENTARIO','$fecha','$hora')",$link);



        
// Ahora comprobaremos que todo ha ido correctamente
        
$my_error mysql_error($link);

        if(!empty(
$my_error)) {

            echo 
"Ha habido un error al insertar los valores. $my_error";

        } else {

           echo 
"<script type=\"text/javascript\">alert('Se Ha Registrado Exitosamente');
        location.href='javascript:history.go(-1)'; </script>"
;

        }

    } else {

        echo 
"<script type=\"text/javascript\">alert('Ocurrio Un Error Usted No Introdujo Todos Los Datos Debe Volver Atras');
        location.href='javascript:history.go(-1)'; </script>"
;

    }

?>

</body>
</html>
y el login.php que es un include que esta en el script donde muestro las fotos y comentarios:
Código PHP:
<?php require_once('Connections/xtremebook.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$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;
}
}
?>
<?php

if (!isset($_SESSION)) {
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['NOMBREUSUARIO'])) {
  
$loginUsername=$_POST['NOMBREUSUARIO'];
  
$password=$_POST['CONTRASENA'];
  
$MM_fldUserAuthorization ="ID";
  
$MM_redirectLoginSuccess "bienvenida.php";
  
$MM_redirectLoginFailed "error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_xtreme_book$xtremebook);
      
  
$LoginRS__query=sprintf("SELECT NOMBREUSUARIO, CONTRASENA, ID FROM registro WHERE NOMBREUSUARIO=%s AND CONTRASENA=%s",
  
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
   
  
$LoginRS mysql_query($LoginRS__query$xtremebook) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
    
    
$loginStrGroup  mysql_result($LoginRS,0,'ID');
    
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset(
$_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
bueno amigos espero su ayuda!