Retrieve and Store the ID from a login screen to use on other CRUD screens

Asked

Viewed 122 times

1

I am specifying as described in the title,recover an id from a select and store it to use on the screens of Crud,I tried to do but still not working thank you already help given,Thanks

HTML Login Screen

<!DOCTYPE html>

<html>
<head>
    <title>Projeto Web-Login</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="_css/layoutPrincipal.css">
    <link rel="stylesheet" href="_css/formulario.css">

   </head>
<body>

<header id="cabecalho">
    <img src="_imagens/logo.jpg">
</header>
<br class="fixFloat">
<nav id="menu">
    <ul>
        <li><a href="index.html" target="_self">Home</a></li>
        <li><a href="cadastra-se.html" target="_self">Cadastra-se</a></li>
        <li><a href="login.html" target="_self">Login</a></li>
    </ul>
</nav>


<section id="form">
   <fieldset id="form_field">
       <legend id="form_legend">Login</legend>
       <form  method="post"  action="_php/login.php" >
           Usuario:<input type="text" name="nome_usuario"><br/><br/>
           Senha:<input type="password" name="Senha"><br/><br/>
           <input id="botao" type="submit" value="Entrar">
           <input type="reset" id="botao" value="Resetar">
       </form>
   </fieldset>



</section>


</body>
</html>

PHP Login Screen

<!DOCTYPE html>

<html>
<head>
    <title>Projeto Web-Login</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../_css/layoutPrincipal.css">
    <link rel="stylesheet" href="../_css/formulario.css">
    <style>

        p{
            font-size: 30px;
            text-align: center;
            font-family: "Arial Black";
        }

    </style>
</head>
<body>

<header id="cabecalho">
    <img src="../_imagens/Logo.jpg">
</header>
<br class="fixFloat">
<nav id="menu">
    <ul>
        <li><a href="../index.html" target="_self">Home</a></li>
        <li><a href="../cadastra-se.html" target="_self">Cadastra-se</a></li>
        <li><a href="../login.html" target="_self">Login</a></li>
    </ul>
</nav>


<section id="form" >

    <?php

    $nome_usuario=$_POST["nome_usuario"];
    $senha=$_POST["Senha"];

    $conexao = mysql_connect("localhost:3306","root","root") or die("Erro durante a conexão do banco de dados");
    mysql_select_db("prestadora",$conexao);
    mysql_query("SET NAMES 'utf8'", $conexao);
    mysql_query('SET character_set_connection=utf8', $conexao);
    mysql_query('SET character_set_client=utf8', $conexao);
    mysql_query('SET character_set_results=utf8', $conexao);
    $verifica="select Nome_Usuario,Senha from cliente where Nome_Usuario = '$nome_usuario' and Senha = '$senha' ";
    $query = mysql_query($verifica);
    mysql_close($conexao);



     session_start();
if($verifica = mysql_fetch_array($query)){


   $verifica['ID_Cliente'] = $_SESSION['ID_Cliente'] ;
   $ID_Cliente = $_SESSION['ID_Cliente']  ;

        echo"<fieldset id='form_field'><legend id='form_legend'>Login</legend><p>Bem-Vindo !!!</p></fieldset>";
        echo '<meta HTTP-EQUIV="Refresh" CONTENT="2; URL=../menucliente.html">';


    }else{

        echo"<fieldset id='form_field'><legend id='form_legend'>Login</legend><p>Usuario e senha não conferem</p></fieldset>";

      echo'<fieldset id="form_field">
        <legend id="form_legend">Voltar</legend>
        <a href="../menucliente.html" id="botao">Voltar</a>
        </fieldset> ';


    }

    ?>


</section>


</body>
</html>

Screen to Query PHP

<!DOCTYPE html>

<html>
<head>
    <title>Projeto Web-ConsultarCadastro</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../_css/layoutPrincipal.css">
    <link rel="stylesheet" href="../_css/formulario.css">
    <style>
    p{
     font-family:"arial black";
     font-size:15px;
     margin: 10px 20px 20px 20px;
      }
    </style>    
</head>
<body>

<header id="cabecalho">
    <img src="../_imagens/Logo.jpg">
</header>
<br class="fixFloat">
<nav id="menu">
    <ul>
        <li><a href="../index.html" target="_self">Home</a></li>
        <li><a href="../cadastra-se.html" target="_self">Cadastra-se</a></li>
        <li><a href="../login.html" target="_self">Login</a></li>
    </ul>
</nav>


<section id="form">
    <?php
    session_start();
    $ID_Cliente = $_SESSION['ID_Cliente'];


    $conexao = mysql_connect("localhost:3306","root","root") or die("Erro durante a conexão do banco de dados");
    mysql_select_db("prestadora",$conexao);
    mysql_query("SET NAMES 'utf8'", $conexao);
    mysql_query('SET character_set_connection=utf8', $conexao);
    mysql_query('SET character_set_client=utf8', $conexao);
    mysql_query('SET character_set_results=utf8', $conexao);
    $consulta= "select * from cliente where ID_Cliente='$ID_Cliente' " ;
    $resultado=mysql_query($consulta,$conexao) or die ("Não foi possível Consultar os seus dados.");
    mysql_close($conexao);


      while($consulta=mysql_fetch_array($resultado)){

          $nome=$consulta["Nome"];
          $email=$consulta['Email'];
          $RG=$consulta['RG'];
          $CPF=$consulta['CEP'];
          $CEP=$consulta['CPF'];
          $sexo=$consulta['Sexo'];
          $endereco=$consulta['Endereco'];
          $bairro=$consulta['Bairro'];
          $cidade=$consulta['Cidade'];
          $estado=$consulta['Estado'];
          $telefone=$consulta['TEL'];
          $celular=$consulta['CEL'];


          echo "<fieldset id='form_field'><legend id='form_legend'>Dados do Usuario</legend>
  <p>Nome:$nome<br/>Email:$email<br/>Sexo:$sexo<br/>RG:$RG<br/>CPF:$CPF<br/>CEP:$CEP<br/>Endereco:$endereco<br/>Bairro:$bairro<br/>
Cidade:$cidade<br/>Estado:$estado<br/>Telefone:$telefone<br/>Celular:$celular<br/></p>
</fieldset>";

          echo'<fieldset id="form_field">
        <legend id="form_legend">Voltar</legend>
        <a href="../menucliente.html" id="botao">Voltar</a>
    </fieldset>';


      }

     ?>


</section>


</body>
</html>

1 answer

1


From what I could see, after checking if the name + password of the user in the bank, you tried to use the id in Session (it will be empty since you did not set the Id_client).

You may notice the problem in these lines here:

if($verifica = mysql_fetch_array($query)){

    $verifica['ID_Cliente'] = $_SESSION['ID_Cliente'];
    $ID_Cliente = $_SESSION['ID_Cliente'];

You need to set $_SESSION['Id_client'] before using.

It would be something like:

if($verifica = mysql_fetch_array($query)){

    $_SESSION['ID_Cliente'] = $verifica['ID_Cliente'];
    $ID_Cliente             = $_SESSION['ID_Cliente'];
  • ai from the following error doing so: Notice: Undefined index: Id_client in C: Program Files (x86) Easyphp-Devserver-14.1VC9 data localweb Service Provider.php login.php on line 58

  • You can leave already solved now just changed the query

  • 1

    looks like : $verifies="select Id_client from client Where Username = '$username' and Password = '$password' ";

Browser other questions tagged

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