Problems with user profile

0

The result of this error page results:

  

Notice: Undefined variable: name in C: \ xampp \ htdocs \ Techphp \ perfil.php   on line 57, line 58, line 59 and line 60,

What are the line where the user profile data is.

What I do not understand is because it is giving this result. Is it not connected?

<?php 
mysql_connect("localhost", "root", "angola") or die("cannot connect");
mysql_select_db("login_senha");


session_start();
$login =  $_SESSION['login_usuario'];

$login =  $_SESSION['login_usuario']=$login;
$sql = mysql_query( "SELECT * FROM usuario WHERE  login='$login'");
while($linha= mysql_fetch_array($sql)){
    $nome=$linha['nome']; 
    $email=$linha['email'];
    $idade=$linha['idade'];
    $cidade=$linha['cidade'] ;
    $foto=$linha['foto'] ;

}
?>


<!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>
<link rel="stylesheet" type="text/css" href="/Techphp/css/estilo.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/Techphp/css/estilo.css"/>
<title>Untitled Document</title>
</head>

<body>
    <div class="container">
    <div class="menu">
    <ul>
        <li>
            <a href="index.php">Voltar</a>
        </li>

        <li>
            <a href="#">Administração</a>

        </li>

    </ul>
    </div>
    <div class="perfil">

      <img src="fotos/<?php echo $foto?>" alt="imagem de perfil" title="imagem de perfil"  />
    </div>

    <div class="dados">
        <p>Nome</p><p><?php echo $nome?></p>    
        <p>Email</p><p><?php echo $email?></p>
        <p>idade</p><p>40<?php echo $idade?></p>    
        <p>Cidade</p><p><?php echo $cidade?></p>

    </div>

    </div>
</body>
</html>  
    
asked by anonymous 03.08.2015 / 15:42

2 answers

0

You can elaborate as follows:

<?php
    session_start();
    mysql_connect("localhost", "root", "angola") or die("cannot connect");
    mysql_select_db("login_senha");

    $login = $_SESSION['login_usuario'];
    $sql = mysql_query( "SELECT * FROM usuario WHERE  login='{$login}'");
    $linha = mysql_fetch_array($sql);

?>
<!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>
<link rel="stylesheet" type="text/css" href="/Techphp/css/estilo.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/Techphp/css/estilo.css"/>
<title>Untitled Document</title>
</head>

<body>
    <div class="container">
    <div class="menu">
    <ul>
        <li>
            <a href="index.php">Voltar</a>
        </li>

        <li>
            <a href="#">Administração</a>

        </li>

    </ul>
    </div>
    <?
    if(mysql_num_rows($sql)>0){
    ?>
    <div class="perfil">
      <img src="fotos/<?php echo $linha['foto']; ?>" alt="imagem de perfil" title="imagem de perfil"  />
    </div>
    <div class="dados">
        <p>Nome</p><p><?php echo $linha['nome']; ?></p>    
        <p>Email</p><p><?php echo $linha['email'];?></p>
        <p>idade</p><p>40<?php echo $linha['idade'];?></p>    
        <p>Cidade</p><p><?php echo $linha['cidade'];?></p>
    </div>
    <? } else {  ?>
     <div class="perfil">
        Este usuário não está logado ou não foi encontrado.
     </div>
    <? } ?>
    </div>
</body>
</html> 

Remembering that Login is coming from session , also check your password to see if it hits your registered password, but in this case it is already logged in? I did not quite understand ... But try to elaborate on my suggestion.

    
03.08.2015 / 16:41
0

Change this section:

$login =  $_SESSION['login_usuario'];

$login =  $_SESSION['login_usuario']=$login;

For this:

if( !isset($_SESSION['login_usuario']))
   die('Usuario nao logado');

$login = $_SESSION['login_usuario'];

And change this section:

$sql = mysql_query( "SELECT * FROM usuario WHERE  login='$login'");

For this:

$sql = mysql_query( "SELECT * FROM usuario WHERE  login='$login'");
if(mysql_num_rows($sql) == 0 )
 die('O usuario '.$login.' não existe');

It will solve or at least help you understand the code itself.

    
03.08.2015 / 17:05