Retrieve and store the ID from a login screen for use on other CRUD screens [closed]

1

I need as described in the title, retrieve an id from a select and store it to use in Crud's screens, I tried to do but it still is not working right thank you since help is already given, thank you

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>

See PHP Screen

<!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>
    
asked by anonymous 20.01.2017 / 20:37

1 answer

1

From what I noticed, after checking the user's name + password in the database, you tried to use the id in the session (it will be empty since you have not set the Customer_ID).

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 ['CustomerID'] before using.

It would look something like this:

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

    $_SESSION['ID_Cliente'] = $verifica['ID_Cliente'];
    $ID_Cliente             = $_SESSION['ID_Cliente'];
    
21.01.2017 / 15:10