1
I don’t know why you’re making this mistake, I’ve gone over everything.
Notice: Undefined index: first
Notice: Undefined index: last name in C: xampp htdocs project registro.php on line 15
Notice: Undefined index: matricula in C: xampp htdocs projeto registro.php on line 16
Notice: Undefined index: email in C: xampp htdocs projeto registro.php on line 17
Notice: Undefined index: password in C: xampp htdocs project record.php on line 18
<?php
$username = 'root';
$password = '';
$connection = new PDO( 'mysql:host=localhost;dbname=*****', $username );
$query = "INSERT INTO usuario (nome, sobrenome, matricula, email, senha)
VALUES (:nome, :sobrenome, :matricula, :email, :senha)";
$statement = $connection->prepare($query);
$valores = array();
$valores[':nome'] = $_POST['primeiroNome'];
$valores[':sobrenome'] = $_POST['sobrenome'];
$valores[':matricula'] = $_POST['matricula'];
$valores[':email'] = $_POST['email'];
$valores[':senha'] = $_POST['senha'];
$result = $statement->execute($valores);
?>
That’s my form right there
<form method="POST" action ="" name="for">
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="primeiroNome">Primeiro nome</label>
<input type="text" class="form-control" id="primeiroNome" name="primeiroNome" placeholder="Digite seu primeiro nome">
</div>
<div class="col-md-6">
<label for="Sobrenome">Sobrenome</label>
<input type="text" class="form-control" id="Sobrenome" name="sobrenome" placeholder="Digite seu Sobrenome">
</div>
</div>
</div>
<div class="col-md-6" id="matricula">
<label for="primeiroNome">Matrícula</label>
<input type="text" class="form-control" name="matricula" placeholder="Digite sua matrícula">
</div>
<div class="form-group">
<label for="email">E-mail</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Digite seu email">
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="senha">Senha</label>
<input type="password" class="form-control" id="senha" name="senha" placeholder="Digite sua senha">
</div>
<div class="col-md-6">
<label for="confirmaSenha">confirmar senha</label>
<input type="password" class="form-control" id="confirmaSenha" name="confirmaSenha" placeholder="Confirme sua senha">
</div>
</div>
</div>
<div>
<input type="submit" class="btn btn-primary btn-block" href="registro.php" value="Registra-se"/>
</div>
<div class="text-center">
<a href="#" class="d-block small mt-3">Esqueceu sua senha?</a>
<a href="#" class="d-block small mt-3">Login?</a>
</div>
</form>
Have you studied the HTTP protocol, which is used on the Web? There are differences between you accessing a page using the GET method and the POST method. You are trying to access data coming in a POST request when it is GET.
– Woss
Your form is displayed and handled on the same page? (
action =""
) If yes, then you should add oneisset
, otherwise it will fail the first time you open the page:$valores[':nome'] = $_POST['primeiroNome'];
would be$valores[':nome'] = (isset($_POST['primeiroNome']) ? $_POST['primeiroNome'] : '');
or, if you use PHP 7+, like this:$valores[':nome'] = ($_POST['primeiroNome'] ?? '');
. I hope I’ve helped!– LipESprY
Translating what @Andersoncarloswoss said, in case it wasn’t clear: when you load the page to fill out the form, you have nothing received via POST. And all your PHP code considers that there will always be data received via POST, which only happens when the form is submitted. In short, you need to check if something was posted before running the PHP snippet shown.
– bfavaretto
Thank you, you’ve helped a lot, you’ve solved my problem.
– Paulo Victor