Problems with the user profile

Asked

Viewed 74 times

0

The result of this error page:

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

Which are the lines where the user profile data is.

Which I don’t understand why this is working. 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>  

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, look also check his password, to see if it matches the registered password, but in this case he is already logged in? I did not understand well... But try to elaborate as I suggest.

  • Okay, I’ll make these changes thank you from my heart

  • Okay! Anything let us know!

  • OK any doubt I’ll give you news

  • It was executed in this order but it appears with the following news: Notice: Undefined index: login_usuario in C: xampp htdocs Techphp profile.php on line 6 this I didn’t understand until the login page is $login = $_SESSION['login_usuario']; I don’t understand what’s wrong with the index of line 6 where it’s registered: $login = $_SESSION['login_usuario'];

  • Where are you looking for Login? It usually comes by Session or post or get?

  • it is in no post: $login = $_POST['login'];

  • Then, just change $login = $_SESSION['login_usuario']; to $login = $_POST['login'];

  • now it shows me the error in line 8: Notice: Undefined variable: login in C: xampp htdocs Techphp profile.php on line 8: $sql = mysql_query( "SELECT * FROM user WHERE login='{$login}'");

  • Swap $sql = mysql_query( "SELECT * FROM usuario WHERE login='{$login}'"); for $sql = mysql_query( "SELECT * FROM user WHERE login='{$login}'") or print mysql_error();

  • Obs:sorry I messed up the line still error on line 6 :Notice: Undefined index: login in C: xampp htdocs Techphp profile.php on line 6: where this the $login = $_POST['login'];

  • I’ll send you the whole process of the pages ok,

  • Okay, put it here in your question.

  • OK I’ll send in the question

Show 8 more comments

0

Change this excerpt:

$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 passage:

$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’ll do, or at least help you understand your own code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.