Change Data with Mysql in PHP searching id from login screen

Asked

Viewed 643 times

-1

TELA DE LOGIN  

<?php

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

    $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'";
    $result=mysql_query($verifica,$conexao) or die ("Não foi possível executa o Login.");
    $count=mysql_num_rows($result);
  
    mysql_close($conexao);


    if($count == 1){

        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>";
    }

    ?>


TELA DE ALTERAR CADASTRO

  <?php
$nome_usuario=$_POST["nome_usuario"];
$senha=$_POST["senha"];
$nome=$_POST["nome"];
$email=$_POST["email"];
$RG=$_POST["RG"];
$CPF=$_POST["CPF"];
$CEP=$_POST["CEP"];
$sexo=$_POST["sexo"];
$endereco=$_POST["end"];
$bairro=$_POST["bairro"];
$cidade=$_POST["cidade"];
$estado=$_POST["estado"];
$telefone=$_POST["tel"];
$celular=$_POST["cel"];



$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);
$atualiza= "update cliente set Nome ='$nome',Sexo ='$sexo',RG ='$RG',CEP ='$CEP',CPF ='$CPF',Estado ='$estado',Cidade ='$cidade',Bairro ='$bairro',Endereco ='$endereco',TEL ='$telefone',CEl ='$celular',Email ='$email',Nome_Usuario ='$nome_usuario',Senha ='$senha' " ;
mysql_query($atualiza,$conexao) or die ("Não foi possível executar a atualização.");
mysql_close($conexao);



echo"<fieldset id='form_field'><legend id='form_legend'>Dados do Usuario</legend>
  $nome_usuario<br/>$senha<br/>$nome<br/>$email<br/>$sexo<br/>$RG<br/>$CPF<br/>$CEP<br/>$endereco<br/>$bairro<br/>
$cidade<br/>$estado<br/>$telefone<br/>$celular<br/>
</fieldset>";



?>

I want to get the id I used on the login screen to change a customer’s data. But I’m out of ideas on how to do this.

  • $_SESSION['id'] = $Count['id'];

2 answers

0

Getting the result of the query:

 $count=mysqli_query($conexao, $result);

then you can check if the login and password have data, if you own, you recover the value

 session_start();
if($row = mysqli_fetch_assoc($conexao, $count)){
   $_SESSION['id'] = $count['id'];
   $id = $_SESSION['id'];

}

So with the recovered code you make your change. I do not recommend using this practice you are using, because it is very insecure, I recommend PDO

$login="update cliente set Nome_Usuario = '$nome_usuario',Senha = '$senha',Status='$Status' WHERE id =  $id ";

There on the other page you call the $id you recovered

session_start();
$id = $_SESSION['id'];
  • 1

    Explain your answer better so that the user who asked understands what motivated you to do this way.

  • Well, what I really wanted is to check and carry the user ID that enabled the login to another php page to change registration

  • ah if so, you store in a session even, I changed the answer to see if that’s right

  • Warning: mysql_result() expects at least 2 Parameters, 1 Given in C: Program Files (x86) Easyphp-Devserver-14.1VC9 data localweb Servicos_php login.php on line 51 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------&#xA;Fatal error: Call to a member function fetch_assoc() on a non-object in C:\Program Files (x86)Easyphp-Devserver-14.1VC9 data localweb Service Provider login.php on line 57

  • is because currently is mysqli and usually he expects the connection and his query, I have changed one

  • Fatal error: Call to Undefined Function mysqli_result() in C: Program Files (x86) Easyphp-Devserver-14.1VC9 data localweb Servicos_php login.php on line 51

  • try it this way: $Count=mysqli_query($connection, $result);

  • There is no need to store id in session. Once logged in it can pick up the id and play straight into a form type=hidden, since the intention is to take the user directly to the profile editing. He can use HTTP methods, in this case, POST. ID, if the primary key is more for database indexing, it would not be a good idea to store in a session.

  • Warning: mysqli_query() expects Parameter 1 to be mysqli, Resource Given in C: Program Files (x86) Easyphp-Devserver-14.1VC9 data localweb Service Providers.php login.php on line 51 ------------------------------------------------------------------------------------------ Warning: mysqli_fetch_assoc() expects Exactly 1 Parameter, 2 Given in C: Program Files (x86) Easyphp-Devserver-14.1VC9 data localweb Servicos_php login.php on line 57

  • http://php.net/manual/en/mysqli.query.php

  • But it is not only to change page but to consult and delete. The login will take you to a menu of options selections and from there goes to the change.

Show 6 more comments

-1

When you log in, save to a $_SESSION['user_id'].

Browser other questions tagged

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