-1
I am trying to make a system in which in my user database has 4 fields: usuario_id
, usuario_nome
, usuario_senha
and usuario_empresa_id
.
I need to capture the data of usuario_empresa_id
(who receives the id
table empresa
when a user makes a company registration together with his login) and put inside the field empresa_id
table deposito
, but inside, when I try to recover the usuario_empresa_id
who is in the Session, he always returns 0
. Someone could explain to me why?
Follows the code:
<?php
session_start();
include('conexao.php');
if(empty($_POST['usuario']) || empty($_POST['senha'])) {
header('Location: index.php');
exit();
}
$usuario = mysqli_real_escape_string($conn, $_POST['usuario']);
$senha = mysqli_real_escape_string($conn, $_POST['senha']);
$query = ("SELECT usuario_id, usuario_nome FROM usuarios
WHERE usuario_nome = '$usuario' AND usuario_senha = '$senha'");
$result = mysqli_query($conn, $query);
$row = mysqli_num_rows($result);
$QR = ("SELECT usuario_empresa_id FROM usuarios WHERE usuario_nome = '$usuario' AND usuario_senha = '$senha'");
$result_qr = mysqli_query($conn, $QR);
$idempresa = mysqli_num_rows($result_qr);
if($row == 1) {
$_SESSION['usuario'] = $usuario;
header('Location: painel.php');
exit();
} else {
$_SESSION['nao_autenticado'] = true;
header('Location: index.php');
exit();
}
if ($_SESSION['usuario']){
$_SESSION['idempresa'] = $idempresa;
}
?>
follows the insertion code in the deposit table
<?php
session_start();
include("conexao.php");
$empresa = $_SESSION['idempresa'];
$deposito = mysqli_real_escape_string($conn, $_POST['deposito']);
$result_deposito = "INSERT INTO depositos(
'deposito_nome',
'deposito_empresa_id')
VALUES(
'$deposito',
'$empresa'
)";
$resultado_deposito = mysqli_query($conn, $result_deposito);
?>
Already gave a var_dump in the variable
$idempresa
?– Vinicius De Jesus
Yeah, it doesn’t point to anything
– Paulo.98
I think you could explain better. In the code shows nothing related to the table "deposit" cited, and in no time you are using
usuario_empresa_id
of the query’s SELECT$QR
. The only thing I see you do is count Rows withmysqli_num_rows
.– Sam
the insertion in the deposit table I try to do in another file calling the $_SESSION['idempresa']. you could tell me how I use the query then?
– Paulo.98
I didn’t quite understand your question. You want to take the amount of $idempresa and put within a session to call elsewhere?
– Marcos Vinicius Leão