Say name after logging in

Asked

Viewed 97 times

0

Good, I’m doing a login system and wanted after I have logged in to my site said welcome... but I’m not able to do that. The only thing I can make appear is welcome and my email..

indexlogin.php:

//LOGIN
$connect = mysql_connect("localhost", "xxxxx", "xxxxxx") or die("Erro");                            // faz a conecxão a base de dados
$db = mysql_select_db("xxxxx",$connect) or die("Erro");                                         // selecionar a base de dados
if(isset($_POST["login"])) {                                                                        // vai verificar se existe
$email =($_POST ["email"]);                                                                     // md5 é a segurança basica. o email fica encrpitado ou se ja eu n vou  saber o email  dele
$password = md5($_POST["password"]);                                                                // o email e a pass são as variaveis
$verificar = mysql_query("SELECT * FROM users WHERE email='$email' AND password='$password'");      // verifica a coluna da base de dados
if (mysql_num_rows($verificar)<=0){                                                             // faz a contagem dos dados que recebeu.                                    
    echo "<h3> Dados de login incorretos!</h3>";                                                    // se não  econtrar os dados da erro
}else{
    setcookie("login",$email);
    header("Location: entrou.php");                                                                     // se econtrar os daods vai para o arquivo entrou.php
}
}

and mine got in.php:

    if(isset($_COOKIE["login"])) {      // apos confirmar os dados ao fazer o login corretramente ira dizer entra na conta.
    echo "BEM VINDO!";
    echo $_COOKIE["login"];
    }else{

    header("Location: ./");   // ./faz com  q vai para logo ao index.
    }
  • 1

    The name would be the login? If yes then you have to set the cookie with the login value setcookie("login",$_POST["login"]) otherwise you have to return the name in the query and set the cookie with this value returned

  • Funny thing is that at no time did the guy attempt to create a variable $login... [facepalm]

  • How so? sorry is that I do programming to around 3/4 months

  • Here the error was hard to find because you don’t have the REGISTER page that is saving the email in the bank so $email = md5($_POST ["email_register"]); e na hora de verificar na pagina indexlogin.php você esta fazendo assim$email =($_POST ["email"]);. O correto é $email =md5($_POST ["email"]);` Editei aresposta

1 answer

2

Here the error was hard to find because it does not have the page REGISTER that is saving the email in the bank so $email = md5($_POST ["email_registar"]); and at the time of checking the indexlogin.php page you are doing so $email =($_POST ["email"]);. The correct is $email =md5($_POST ["email"]); I edited the answer. REGISTER page I saw in another question your Login for admistradores and customers

Return the user name in the declaration SELECT.

indexlogin.php

    $connect = mysql_connect("localhost", "xxxxx", "xxxxxx") or die("Erro");                            
    // faz a conecxão a base de dados
    $db = mysql_select_db("xxxxx",$connect) or die("Erro");                                         
    // selecionar a base de dados
    if(isset($_POST["login"])) {  
                                                                         // 
    //vai verificar se existe
    /*********** aqui o seu erro *********/
    //$email =($_POST ["email"]); 

    /******* correto ************/ 
    $email =md5($_POST ["email"])


   // md5 é a segurança basica. o email fica encrpitado ou se ja eu n vou  saber o email  dele
    $password = md5($_POST["password"]);

    $verificar = "SELECT * FROM users WHERE email='$email' AND password='$password'";
    $res = mysql_query($verificar) or die(mysql_error());
        if(mysql_num_rows($res)>0){
           $row = mysql_fetch_array($res);

           // aqui está retornando o nome para setar o cookie com ele
           $nome = $row['nome'];

           setcookie("nome",$nome);
           header("Location: entrou.php"); 
        }else{
           echo "<h3> Dados de login incorretos!</h3>";
        }
    }

entered php.

if(isset($_COOKIE["nome"])) {      // apos confirmar os dados ao fazer o login corretarmente ira dizer entra na conta.
echo "BEM VINDO!";
/***********************************
 pega o cookie com o nome do usuario
***********************************/
echo $_COOKIE["nome"];

}else{

header("Location: ./");   // ./faz com  q vai para logo ao index.
}

OBS: Why should we not use mysql type functions_*?

  • how so n works... Thanks for the help.. but n is working.. thank you anyway :/

  • @Lucassintra, you have to show the code that’s not working?

  • n is n work. It’s that keeps saying welcome and then my email. and I wanted you to tell me my name. I already have the name entered in my database.

  • @Lucassintra, is because you saved the cookie with the email right. See in the reply, item 2 Criar cookie com NOME do usuario how it should be done, create a cookie with the name coming from the bank and then recover it in.php with echo $_COOKIE["login"];Regardless of this comment I edited the answer putting more details.

  • look I really appreciate your help so much. Thank you. but let it be. until next!!

  • @Lucassintra, still can’t get it? What is the name of the column in the database table that contains the name ?

  • I have the database which is a23144 and then a table for the login system which is users. which has the id, name, email, password, and the date.

Show 2 more comments

Browser other questions tagged

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