Notice: Undefined index [duplicate]

1

I do not know why you're giving this error, I've already reviewed everything.

Notice: Undefined index: firstName in C: \ xampp \ htdocs \ project \ log.php on line 14

Notice: Undefined index: last name in C: \ xampp \ htdocs \ project \ log.php on line 15

Notice: Undefined index: matricula in C: \ xampp \ htdocs \ project \ record.php on line 16

Notice: Undefined index: email in C: \ xampp \ htdocs \ project \ log.php on line 17

Notice: Undefined index: password in C: \ xampp \ htdocs \ project \ log.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);




    ?>

This is my form

<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>
    
asked by anonymous 03.10.2018 / 22:49

1 answer

0

The problem occurs because you put the href attribute in the submit input and do not put the record.php in the action of the form. Remove the attribute add action and try again. I leave your edited HTML below.

<form method="POST" action="registro.php" 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" 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>
    
04.10.2018 / 00:43