1
I am making a registration page using PHP. I have a validation to show the user if the registration has been done or not, but is always returning Notice: Undefined index: status_cadastro in C:\xampp\htdocs\login-php-usb\cadastro.php on line 25
.
HTML:
<?php
if($_SESSION['status_cadastro']):
?>
<div class="notification is-success">
<p>Cadastro efetuado!</p>
<p>Faça login informando o seu usuário e senha <a href="login.php">aqui</a></p>
</div>
<?php
endif;
unset($_SESSION['status_cadastro']);
?>
Filing cabinet register.php with the Sesssions:
<?php
session_start();
include("conexao.php");
$nome = mysqli_real_escape_string($conexao, trim($_POST['nome']));
$usuario = mysqli_real_escape_string($conexao, trim($_POST['usuario']));
$senha = mysqli_real_escape_string($conexao, trim(md5($_POST['senha'])));
$sql = "select count(*) as total from usuario_web where usuario = '$usuario'";
$result = mysqli_query($conexao, $sql);
$row = mysqli_fetch_assoc($result);
if($row['total'] == 1) {
$_SESSION['usuario_existe'] = true;
header('Location: cadastro.php');
exit;
}
$sql = "INSERT INTO usuario_web (nome, usuario, senha, data_cadastro) VALUES ('$nome', '$usuario', '$senha', NOW())";
if($conexao->query($sql) === TRUE) {
$_SESSION['status_cadastro'] = true;
}
$conexao->close();
header('Location: cadastro.php');
exit;
?>
I think the mistake is with Septssion, but I couldn’t identify, anyone would have any idea?
You even started Session in this file that contains html ?
– Gato de Schrödinger
@Thiagopetherson:
<?php
session_start();
?>
<!DOCTYPE html>
<html>

– Algeu Junior
The line 25 being mentioned in the error message is that of unset or IF ?
– Gato de Schrödinger
@Thiagopetherson would do if. https://ibb.co/m8L5ffH
– Algeu Junior
@Algeujunior, you know what’s going on. I believe you’re trying to access a Session attribute before it’s created. Type. You are rendering HTML before you started Session . with this attribute. type $_SESSION['status_registration'] = false; if($connected->query($sql) === TRUE) { $_SESSION['status_registration'] = true; }
– Marcus Italo