-1
the two files that make connection
and that:
<?php
include("classe/conexao.php");
if(isset($_POST['confirmar'])){
//1- Registro dos dados
if(!isset($_SESSION))
session_start();
foreach($_POST as $chave=>$valor){
$_SESSION[$chave] = $mysqli-> 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){
$sql_code = "INSERT INTO usuario(
nome,
sobrenome,
sexo,
email,
senha,
nivelacesso
)
VALUES(
'$_SESSION[nome]',
'$_SESSION[sobrenome]',
'$_SESSION[sexo]',
'$_SESSION[email]',
'$_SESSION[senha]',
'$_SESSION[nivelacesso]'
)";
$confirma = $mysqli->query($sql_code) or die($mysqli->error);
if($confirma){
unset($_SESSION[nome],
$_SESSION[sobrenome],
$_SESSION[sexo],
$_SESSION[email],
$_SESSION[senha],
$_SESSION[nivelacesso]);
echo "<script> location.href='index.php?p=inicial'</script>";
}else
$erro[] = $confirma;
}
}
?>
<h1>Cadastrar Usuário</h1>
<?php
if(count($erro)> 0){
echo "<div class='erro'>";
foreach($erro as $valor)
echo "$valor <br>";
echo "</div>";
}
?>
<a href="index.php?p=inicial">voltar</a>
<form action="index.php?p=cadastrar" method="post">
<!-- nome -->
<label for="nome">Nome</label>
<input type="text" name="nome" id="nome" value="" 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">
<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="">basico</option>
<option value="">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" value="">
<p class="espaco"></p>
<!-- repita a senha -->
<label for="rsenha">Repita a Senha</label>
<input type="password" name="rsenha" id="rsenha" value="">
<p class="espaco"></p>
<input type="submit" value="Salvar" nome="confirmar">
</form>
with that:
<?php
$host ="localhost";
$user="root";
$pass="";
$banco="labrador";
$conexao=mysqli_connect($host, $user, $pass,$banco) or die(mysqli_error());
mysqli_select_db($conexao,$banco) or die(mysqli_error());
?>
I don’t know what’s going on that helps me with this code please?
Notice: Undefined variable: error in C: xampp htdocs Complete Registration system contains.php on line 83 this error is giving in my code and do not know pq, could help,
– Hugo LELIS
@Hugolelis, what’s on line 83?
– user60252
if(is_countable($error) && Count($error) > 0){
– Hugo LELIS
the variable $error is undefined, it is undefined and does not let me upload the code
– Hugo LELIS
@Hugolelis, The question(s) problem was/were solved(s) and you did not signal the answer as accepted and already amended with another question that is not the focus of this post. The correct one would be to make another post with this new situation. For this new situation declare the variable $error at the beginning of the code $error=[];
– user60252
@Hugolelis, actually there are still more errors in your script besides this $error being as undefined. But it’s like I told you, the focus of the question is Parameter must be an array or an Object that Implements Countable in that was solved with the answer and even more so the Fatal error: Uncaught Error: Call to a Member Function real_escape_string() on null in was also given as a bonus.
– user60252
@Hugolelis, why don’t you ask him why he’s working with so many women? It’s not the best way to work since you might for some reason miss the Sesssions.
– user60252
I’m learning php now I have no idea why use so many Sessions
– Hugo LELIS
@Hugolelis, it is, so learn and do it right as the last of the answer.
– user60252
Of course my dear colleague, I apologize for the delay of not responding fast, you could indicate me something to study in the correct way?
– Hugo LELIS