0
The following error is appearing: Notice: Undefined variable: u in C: Webserver Apache2.2 htdocs posts register.php on line 30 Fatal error: Call to a Member Function connect() on a non-object in C: Webserver Apache2.2 htdocs posts register.php on line 30
I tried in some ways to solve the problem, but it’s not working, as I can solve?
<html lang="pt-br" >
<head>
<title>Projeto Login</title>
<meta charset="UTF-8" />
<link rel="stylesheet" href="css/login.css" />
</head>
<body>
<div id="corp-form" >
<form method="POST" >
<h1>Cadastrar</h1>
<input type="text" name="nome" placeholder="Nome completo" maxlength="30" />
<input type="email" name="email" placeholder="Usuário" maxlength="30" />
<input type="password" name="senha" placeholder="Senha" maxlength="16" />
<input type="password" name="confSenha" placeholder="Confirmar a senha" maxlength="16" />
<input type="submit" name="submit" value="Cadastrar" />
</form>
</div>
<?php
date_default_timezone_set('America/Sao_Paulo');
if(isset($_POST['nome']))
{
$nome = $_POST['nome'];
$email = addslashes($_POST['email']);
$senha = addslashes($_POST['senha']);
$confirmarSenha = addslashes($_POST['confSenha']);
//verificar se esta preenchido
if(!empty($nome) && !empty($email) && !empty($senha)
&& !empty($confirmarSenha))
{
$u->conectar("projeto_login","localhost","root","");
if($nome->msgErro == "")
{
if($senha == $confirmarSenha)
{
if($u->cadastrar($nome,$email,$senha))
{
echo "Cadastrado com sucesso! Acesse para entrar.";
}
else
{
echo "Email já cadastrado!";
}
}
else
{
echo "Senha e confirmar senha não correspondem!";
}
}
else
{
echo "Erro: ".$u->msgErro;
}
}else
{
echo "Preencha todos os campos!";
}
}
?>
</body>
</html>
From what I understand my variable "u" is not defined, I have defined in other ways, but it did not work.
where you declared the "u", I see neither include from another file nor her statement
– João Vitor
Along with that part $name = $_POST['name']; $email = addslashes($_POST['email']); $password = addslashes($_POST['password']); $confirm = addslashes($_POST['confNow']); I declared it as a set of all these, but it failed. I did not declare it in this code because apparently I am not able to declare it correctly.
– Mikael
Has no variable declaration
$u
in your code. It is in some external file?– João Vitor
@Joãovitor I set it in my index.php <?php date_default_timezone_set('America/Sao_paulo'); require_once 'CLASSES/usuarios.php'; $u = new Usuario; ? > <html lang="en" > <head> <title>Project Login</title> <meta charset="UTF-8" /> <link rel="stylesheet" href="css/login.css" /> </head>
– Mikael