-1
Hello I would like to put the values in the input so that if I press the Submit without having the other information I do not miss what has already been filled
I thought putting inside the "value" would work as already putting:
value="<?= $_SESSION['nome']; ?>"
but no error occurs:
<br /><b>Notice</b>: Undefined variable: _SESSION in <b>C:\xampp\htdocs\Completo Sistema de cadastro\conteudo\cadastrar.php</b> on line <b>101</b><br /><br /><b>Notice</b>: Trying to access array offset on value of type null in <b>C:\xampp\htdocs\Completo Sistema de cadastro\conteudo\cadastrar.php</b> on line <b>101</b><br />
My code and this one below:
How can I do that:
<?php
$erro = [];
include("classe/conexao.php");
if(isset($_POST['confirmar'])){
//1- Registro dos dados
if(!isset($_SESSION))
session_start();
foreach($_POST as $chave=>$valor){
$_SESSION[$chave] = $conexao-> real_escape_string($valor);
}
//2- Validação dos dados
if(strlen($_SESSION['nome']) == 0 )
$erro[] = "Preencha o Nome ";
if(strlen($_SESSION['sobrenome']) == 0 )
$erro[] = "Preencha o Sobrenome ";
if(strlen($_SESSION['sexo']) == 0 )
$erro[] = "Selecione o Sexo ";
if(substr_count($_SESSION['email'],'@') !==1 ||substr_count($_SESSION['email'], '.') < 1 || substr_count($_SESSION['email'], '.') > 2)
$erro[] = "Preencha o Email corretamente ";
if(strlen($_SESSION['nivelacesso']) == 0 )
$erro[] = "Preencha seu Nivel de Acesso ";
if(strlen($_SESSION['senha']) < 8 || strlen($_SESSION['senha']) > 16 )
$erro[] = " Preencha a senha correntamente ";
if(strcmp($_SESSION['senha'], $_SESSION['rsenha'])!= 0 )
$erro[] = "As senhas não batem ";
//3- Inserção no Banco e redirecionamento
if(count($erro) == 0){
$senha= md5(md5($_SESSION['senha']));
$sql_code = "INSERT INTO usuario(
nome,
sobrenome,
sexo,
email,
senha,
nivelacesso,
datacadastro
)
VALUES(
'$_SESSION[nome]',
'$_SESSION[sobrenome]',
'$_SESSION[sexo]',
'$_SESSION[email]',
'$senha',
'$_SESSION[nivelacesso]',
NOW()
)";
$confirma = $conexao->query($sql_code) or die($conexao->error);
if($confirma){
unset($_SESSION[nome],
$_SESSION[sobrenome],
$_SESSION[sexo],
$_SESSION[email],
$_SESSION[senha],
$_SESSION[nivelacesso],
$_SESSION[datacadastro]
);
echo "<script> location.href='index.php?p=inicial'</script>";
}else
$erro[] = $confirma;
}
}
?>
<h1>Cadastrar Usuário</h1>
<?php
if(is_countable($erro) && count($erro) > 0){
echo "<div class='erro'>";
foreach($erro as $valor)
echo "$valor <br>";
echo "</div>";
}
?>
<a href="index.php?p=inicial" class="link_vo">voltar</a>
<form action="index.php?p=cadastrar" method="post">
<!-- nome -->
<label for="nome">Nome</label>
<input type="text" name="nome" id="nome" value="<?php $_SESSION['nome']; ?>"" require>
<p class="espaco"></p>
<!-- sobrenome -->
<label for="sobrenome">Sobrenome</label>
<input type="text" name="sobrenome" id="sobrenome" value="" require>
<p class="espaco"></p>
<!-- sexo -->
<label for="sexo">Sexo</label>
<select name="sexo" id="sexo" value="">
<option value="" >Selecione</option>
<option value="1">Masculino</option>
<option value="2">Feminino</option>
</select>
<p class="espaco"></p>
<!-- email -->
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" require>
<p class="espaco"></p>
<!-- nivelacesso -->
<label for="nivelacesso">Nível De acesso</label>
<select name="nivelacesso" id="nivelacesso" >
<option value="" >Selecione</option>
<option value="1">basico</option>
<option value="2">admin</option>
</select>
<p class="espaco"></p>
<!-- senha -->
a senha deve ter entre 8 e 16 caracteres
<label for="senha">Senha</label>
<input type="password" name="senha" id="senha">
<p class="espaco"></p>
<!-- repita a senha -->
<label for="rsenha">Repita a Senha</label>
<input type="password" name="rsenha" id="rsenha">
<p class="espaco"></p>
<input type="submit" value="Salvar" name="confirmar" class="btn">
<input type="reset" value="Limpar" class="btn">
</form>
Virgilio’s answer in his code won’t work, I could help you with your question, but I don’t know why, I think, you didn’t like me. In your previous question I solved your problem and I anticipated all the others that would occur and you did not accept my answer and I understood this as ingratitude since you did not interact with me anymore.
– user60252
I’m new on the platform if I’m sorry I’m picking up a bit yet
– Hugo LELIS
Saturday night I will post a full reply.
– user60252