-3
When I try to open the php file the following errors appear:
Notice: Undefined index: name in D: Xampp htdocs web2 php conexao.php on line 14
Notice: Undefined index: email in D: Xampp htdocs web2 php conexao.php on line 15
Notice: Undefined index: RG in D: Xampp htdocs web2 php conexao.php on line 16
Notice: Undefined index: senhaconfirm in D: Xampp htdocs web2 php conexao.php on line 17
HTML
<form id="register-form" method="POST" action="/conexao.php">
<div class="col-md-6 register-top-grid">
<div>
<label for="email">E-mail</label>
<input type=text id="email" name="email" placeholder="Digite seu e-mail" maxlenght="50"
data-min-length="2" data-email-validate>
</div>
<div>
<label for="name">Nome</label>
<input type="text" name="nome" id="nome" placeholder="Digite seu nome" data-required
data-min-length="3" data-max-length="40">
</div>
<div>
<label for="lastname">RG</label>
<input type="text" name="RG" id="RG" placeholder="Digite seu RG" data-required
data-only-letters>
</div>
<a class="news-letter">
<input type="checkbox" name="termos" id="agreement">
<label for="agreement" id="agreement-label">Eu li e aceito os termos de uso</label>
<p><a class="termos-de-uso" href="#">termos de uso</a></p>
<br>
</a>
</div>
<div class="col-md-6 register-bottom-grid">
<div>
<label for="lastname">Senha</label>
<input type="password" name="senha" id="senha" placeholder="Digite sua senha"
data-password-validate data-required>
</div>
<div>
<label for="passconfirmation">Confirmação de senha</label>
<input type="password" name="senhaconfirm" id="senhaconfirm"
placeholder="Digite novamente sua senha" data-equal="password">
</div>
<div class="full-box">
<input id="btn-submit" type="submit" value="Registrar">
</div>
</div>
</form>
PHP
<?php
$hostname = "localhost";
$user = "root";
$password = "root";
$database = "cadastros";
$conexao = mysqli_connect($hostname,$user,$password,$database);
if(!$conexao){
print "Falha na conexão";
}
$nome = $_POST['nome'];
$email = $_POST['email'];
$RG = $_POST['RG'];
$senha = $_POST['senhaconfirm'];
$sql = "insert into usuarios (nome,email,RG,senha) values ('$nome','$email','$RG','$senha')";
$Registrar = mysqli_query($conexao,$sql);
mysqli_close($conexao)
?>
you have undefined variables and your PHP is configured to display notices, errors and warnings, either you change the display of notices or you set your variables before using them, or you can also make use of isset($var) to check if the variable was set before using it.
– ElvisP
You can also place all PHP within this conditional if(isset($_POST) && ! Empty($_POST)){
– user60252
Don’t forget to close with the } key at the end
– user60252