Id of the users table from the login

1

Users table: iduser, name, user, password, group In the login you must enter username, password and group

<?php
include('00_conn.php');
$consulta = "SELECT * FROM $t98 WHERE (98_username= '$usuario' AND 98_clave = '$clave' AND '98_grupo = '$grupo')";
$respuesta = mysqli_query($conexion, $consulta);

if( $fila = mysqli_fetch_row($respuesta) ) fila
{
   if (password_verify($clave,$fila)) {
        session_start();  //habilita uso de sesiones
        $_SESSION['username'] = $username;
        $_SESSION['grupo'] = $grupo; 
        $_SESSION['username'] = $username;   }
}
?>

Specifically: how can I get the Iduser and take it as a variable to embed it in every intervention I have in the bbdd load? I hope I was clear! Thank you very much!

    
asked by Silvia Gaviota Garcia 20.09.2017 в 00:30
source

2 answers

1

Use this to see if it works for you, where are the variables of $ _SESSION you put the ones that you want to take to manage in the system, besides that you are repeating username 2 times ...

$consulta = "SELECT * FROM elnombredetutabla WHERE 98_username='$usuario' and 98_clave='$clave'";
$query = mysqli_query($conexion,$consulta);
	if(isset($_POST['usuario']) && isset($_POST['clave'])){
	{
		if(mysqli_num_rows($query) > 0)
		{
			if($row =mysqli_fetch_assoc($query))
			{ 
				$_SESSION['id'] = $row['iduser'];
				$_SESSION['username'] = $username;
                $_SESSION['grupo'] = $grupo; 
				
				header('Location: ./lapaginaquequieresmostrar.php');
			}
		}
		else
		{
			echo '<script> alert("Usuario o contraseña incorrectos."); </script>';
		}
    
answered by 20.09.2017 / 07:06
source
1

This up to here works as perfect, divine, send me where I ask and everything! so here we CLOSE (I do not know how it's done) and it's coming in the next novel .. a) how to recover the idusr in another page b) how to take the user to the corresponding menu according to their group (I guess with case and switch and all that. For now ... thank you and I leave with a slight bowing of the head and torso thanking the answers given!

<?php
    session_start();
    ob_start();
require('00_0encab.inc');
require('00_1menu_usuar.inc');
include('/Connections/00_conn.php');
$username= $_POST['username'];
$clave= $_POST['clave'];
$consulta = "SELECT * FROM $t98 WHERE 98_username='$username' and 98_clave='$clave'";
$query = mysqli_query($conexion,$consulta);
    if(isset($_POST['username']) && isset($_POST['clave'])){
    {
        if(mysqli_num_rows($query) > 0)
        {
            if($row =mysqli_fetch_assoc($query))
            { 
                $_SESSION['id'] = $row['98_idusr'];
                $_SESSION['username'] = $username;
                $_SESSION['clave'] = $clave; 


                header('Location: Index_adm.php');
            }
        }
        else
        {
            echo '<script> alert("Usuario o contraseña incorrectos."); </script>';
        }   
    }
        mysqli_close($conexion);
    }
?>
    
answered by 20.09.2017 в 23:18