html form for mysql database does not record

1

I'm a beginner in PHP, and since I'm already full of doubts and looking to learn some techniques and so on, I'm using a form template that I want to play in the database, it will not work when I click in send, says that it was successful but does not record in the bank ... Can someone there give me a hand? I'm going to post the php code I should write to the bank. I thank the attention! ; )

File code I created: grava_cheklist.php

<?php
    include "conexao.php";

    $responsavel = $_POST['responsavel'];
    $placa = $_POST['placa'];
    $veiculo = $_POST['veiculo'];
    $cor = $_POST['cor'];
    $combustivel = $_POST['combustivel'];
    $pneus = $_POST['pneus'];
    $kilometragem = $_POST['kilometragem'];
    $paradiante = $_POST['paradiante'];
    $teto = $_POST['teto'];
    $traseira = $_POST['traseira'];
    $paratraseiro = $_POST['paratraseiro'];
    $paralamad = $_POST['paralamad'];
    $paralamae = $_POST['paralamae'];
    $portam = $_POST['portam'];
    $portac = $_POST['portac'];
    $ptrasd = $_POST['ptrasd'];
    $ptrase = $_POST['ptrase'];
    $parabrisa = $_POST['parabrisa'];
    $dia = $_POST['dia'];
    $mes = $_POST['mes'];
    $ano = $_POST['ano'];
    $nome_cliente = $_POST['nome_cliente'];
    $sobrenome = $_POST['sobrenome'];
    $telefone = $_POST['telefone'];
    $bairro = $_POST['bairro'];
    $cidade = $_POST['cidade'];
    $documento = $_POST['documento'];
    $email = $_POST['email'];
    $observacao = $_POST['observacao'];

    $result_cadastro = "INSERT INTO cadastro(responsavel, placa, veiculo, cor, combustivel, pneus, kilometragem, paradiante, teto, traseira, paratraseiro, paralamad, paralamae, portam, portac, ptrasd, ptrase, parabrisa, dia, mes, ano, nome_cliente, sobrenome, telefone, bairro, cidade, documento, email, observacao) VALUES ('$responsavel','$placa','$veiculo','$cor','$combustivel','$pneus','$kilometragem','$paradiante','$teto','$traseira','$paratraseiro','$paralamad','$paralamae','$portam','$portac','$ptrasd','$ptrase','$parabrisa','$dia','$mes','$ano','$nome_cliente','$sobrenome','$telefone','$bairro','$cidade','$documento','$email','$observacao')";
    $resultado_cadastro = mysqli_query($conn, $result_cadastro); 
    if(mysqli_affected_rows($conn) != 0){
                echo "Veiculo cadastrado com Sucesso";
            }else{
                echo "O veiculo não foi cadastrado com Sucesso.";   
     }

?>

This is the form:

            <form method="POST" action="grava_cheklist.php">
                <ul class="field-list">
                    <li>
                        <label class="form-label">
                          Responsável:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="responsavel" required>
                                <option value="">&nbsp;</option>
                                <option value="André"> André </option>
                                <option value="Tibolla"> Avelino Tibolla </option>
                                <option value="Atendimento"> Atendimento </option>
                                <option value="cliente"> Cliente </option>
                            </select>
                        </div>
                        </li>
                  <li>
                     <label class="form-label"> 
                           Placa:
                            <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <input type="text" name="placa" maxlength="7" placeholder="Entrar com a placa do carro" required >
                        </div>
                    </li>
                    <li>
                     <label class="form-label"> 
                           Veículo:
                            <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <input type="text" name="veiculo" maxlength="20" placeholder="Entrar com o nome do carro" required >
                        </div>
                    </li>
                    <li>
                        <label class="form-label">
                           Cor:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="cor" required>
                                <option value="">&nbsp;</option>
                                <option value="Branco"> Branco </option>
                                <option value="Preto"> Preto </option>
                                <option value="Cinza"> Cinza </option>
                                <option value="Vermelho"> Vermelho </option>
                                <option value="Marrom"> Marrom </option>
                                <option value="Verde"> Verde </option>
                                <option value="Amarelo"> Amarelo </option>
                                <option value="Bordo"> Bordo </option>
                                <option value="Cinza"> Cinza </option>
                                <option value="Azul"> Azul </option>
                                <option value="outros"> Outros </option>
                            </select>
                        </div>
                        </li>
                        <li>
                        <label class="form-label">
                           Combustível:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="combustivel" required>
                                <option value="">&nbsp;</option>
                                <option value="reseva"> reserva </option>
                                <option value="cheio"> Cheio </option>
                                <option value="1/3"> 1/3 </option>
                                <option value="3/4"> 3/4 </option>
                                <option value="meio"> meio </option>
                                <option value="vazio"> Vazio </option>
                                <option value="outros"> Outros </option>
                            </select>
                        </div>
                            </li>
                        <li>
                        <label class="form-label">
                           Pneus:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="pneus" required>
                                <option value="">&nbsp;</option>
                                <option value="bons"> Bons </option>
                                <option value="ruins"> Ruins </option>
                                <option value="novos"> Novos </option>
                                <option value="outros"> Outros </option>
                            </select>
                          </div>
                       </li>
                     <li> 
                        <label class="form-label">
                           Kilometragem:
                          <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <input type="text" name="kilometragem" maxlength="20" placeholder="Kilometragem" required>
                        </div>
                    </li>
                    <li>
                        <label class="form-label">
                           Parachoque Diant.:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="paradiante" required>
                                <option value="">&nbsp;</option>
                              <option value="OK"> OK </option>
                              <option value="Risco"> Risco </option>
                              <option value="Amassado"> Amassado </option>
                              <option value="Manchado"> Manchado </option>
                              <option value="Quebrado"> Quebrado </option>
                              <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                        </li>
                     <li>
                        <label class="form-label">
                           Teto:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="teto" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassado"> Amassado </option>
                                <option value="Manchado"> Manchado </option>
                                <option value="Quebrado"> Quebrado </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                         </li>
                     <li>
                        <label class="form-label">
                           Tampa Traseira:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="traseira" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassada"> Amassada </option>
                                <option value="Manchada"> Manchada </option>
                                <option value="Quebrado"> Quebrada </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                         </li>
                     <li>
                        <label class="form-label">
                           Parachoque Tras.:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="paratraseiro" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassado"> Amassado </option>
                                <option value="Manchado"> Manchado </option>
                                <option value="Quebrado"> Quebrado </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                         </li>
                     <li>
                        <label class="form-label">
                           Paralama Dir.:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="paralamad" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassado"> Amassado </option>
                                <option value="Manchado"> Manchado </option>
                                <option value="Quebrado"> Quebrado </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                         </li>
                     <li>
                        <label class="form-label">
                           Paralama Esq.:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="paralamae" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassado"> Amassado </option>
                                <option value="Manchado"> Manchado </option>
                                <option value="Quebrado"> Quebrado </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                         </li>
                     <li>
                        <label class="form-label">
                           Porta do Motorista:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="portam" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassada"> Amassada </option>
                                <option value="Manchada"> Manchada </option>
                                <option value="Quebrada"> Quebrada </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                         </li>
                      <li>
                        <label class="form-label">
                           Porta do Carona:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="portac" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassada"> Amassada </option>
                                <option value="Manchada"> Manchada </option>
                                <option value="Quebrada"> Quebrada </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                          </li>
                     <li>
                        <label class="form-label">
                           Porta tras. Dir.:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="ptrasd" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassada"> Amassada </option>
                                <option value="Manchada"> Manchada </option>
                                <option value="Quebrada"> Quebrada </option>
                                <option value="Sem esta Porta"> Sem esta Porta </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                         </li>
                     <li>
                        <label class="form-label">
                           Porta tras. Esq.:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="ptrase" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Amassada"> Amassada </option>
                                <option value="Manchada"> Manchada </option>
                                <option value="Quebrada"> Quebrada </option>
                                <option value="Sem esta Porta"> Sem esta Porta </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                         </li>
                      <li>
                        <label class="form-label">
                           Parabrisa:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <select class="form-dropdown" name="parabrisa" required>
                                <option value="">&nbsp;</option>
                                <option value="OK"> OK </option>
                                <option value="Risco"> Risco </option>
                                <option value="Trincado"> Trincado </option>
                                <option value="Manchado"> Manchado </option>
                                <option value="Quebrado"> Quebrado </option>
                                <option value="Ver Nas Observações"> Ver Nas Observações </option>
                            </select>
                        </div>
                    </li>
                     <li>
                        <label class="form-label">
                           Data de Hoje:
                          <span class="form-required"> * </span>
                        </label>
                        <div class="form-input dob">
                            <span class="form-sub-label">
                                <select name="dia" class="Dia">
                                    <option>&nbsp;</option>
                                    <option value="1"> 1 </option>
                                    <option value="2"> 2 </option>
                                    <option value="3"> 3 </option>
                                    <option value="4"> 4 </option>
                                    <option value="5"> 5 </option>
                                    <option value="6"> 6 </option>
                                    <option value="7"> 7 </option>
                                    <option value="8"> 8 </option>
                                    <option value="9"> 9 </option>
                                    <option value="10"> 10 </option>
                                    <option value="11"> 11 </option>
                                    <option value="12"> 12 </option>
                                    <option value="13"> 13 </option>
                                    <option value="14"> 14 </option>
                                    <option value="15"> 15 </option>
                                    <option value="16"> 16 </option>
                                    <option value="17"> 17 </option>
                                    <option value="18"> 18 </option>
                                    <option value="19"> 19 </option>
                                    <option value="20"> 20 </option>
                                    <option value="21"> 21 </option>
                                    <option value="22"> 22 </option>
                                    <option value="23"> 23 </option>
                                    <option value="24"> 24 </option>
                                    <option value="25"> 25 </option>
                                    <option value="26"> 26 </option>
                                    <option value="27"> 27 </option>
                                    <option value="28"> 28 </option>
                                    <option value="29"> 29 </option>
                                    <option value="30"> 30 </option>
                                    <option value="31"> 31 </option>
                                </select>
                                <label class="form-sub-label1"> Dia </label>
                            </span>
                          <span class="form-sub-label">
                                <select name="mes" class="mes">
                                    <option>&nbsp;</option>
                                    <option value="Janeiro"> Janeiro </option>
                                    <option value="Fevereiro"> Fevereiro </option>
                                    <option value="Março"> Março </option>
                                    <option value="Abril"> Abril </option>
                                    <option value="Maio"> Maio </option>
                                    <option value="Junho"> Junho </option>
                                    <option value="Julho"> Julho </option>
                                    <option value="Agosto"> Agosto </option>
                                    <option value="Setembro"> Setembro </option>
                                    <option value="Outubro"> Outubro </option>
                                    <option value="Novembro"> Novembro </option>
                                    <option value="Dezembro"> Dezembro </option>
                                 </select>
                                <label class="form-sub-label1"> Mês </label>
                            </span> 
                            <span class="form-sub-label">
                                <input type="text" class="year" name="ano" size="4" maxlength="4" placeholder="Ano" required>
                                <label class="form-sub-label1"> Ano </label>
                            </span>
                        </div>
                    </li>
                    <li> 
                        <label class="form-label">
                           Cliente Nome/Sobrenome:
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input add">
                            <span class="form-sub-label">
                                <input type="text" name="nome_cliente" maxlength="50" placeholder="Nome" required>
                                <label class="form-sub-label1"> Nome </label>
                            </span>
                            <span class="form-sub-label">
                                <input type="text" name="sobrenome" maxlength="50" placeholder="Sobrenome" required>
                                <label class="form-sub-label1"> Sobrenome </label>
                            </span>
                            <span class="form-sub-label">
                                <input type="text" name="telefone" placeholder="Telefone" size="11" maxlength="11" required>
                                <label class="form-sub-label1"> Telefone </label>
                            </span>
                            <span class="form-sub-label">
                                <input type="text" name="bairro" placeholder="Bairro" maxlength="20" required>
                                <label class="form-sub-label1"> Bairro </label>
                            </span>
                            <span class="form-sub-label">
                                <input type="text" name="cidade" placeholder="Cidade" maxlength="20" required>
                                <label class="form-sub-label1"> Cidade </label>
                            </span>
                            <span class="form-sub-label">
                                <input type="text" name="documento" placeholder="Documento" size="11" maxlength="11" required>
                                <label class="form-sub-label1"> Documento </label>
                            </span>
                        </div>
                    </li>
                    <li> 
                        <label class="form-label">
                           E-Mail do Cliente
                           <span class="form-required"> * </span>
                        </label>
                        <div class="form-input">
                            <input type="email" name="email" placeholder="[email protected]" maxlength="50" required>
                        </div>
                    </li>
                    <li> 
                        <label class="form-label1">
                            Observações do Chek-list do Veículo
                        </label>
                        <div class="form-input2">
                            <textarea rows="5" cols="20" name="observacao" maxlength="200"></textarea>
                        </div>
                    </li>
                    <li class="last-type"> 
                        <label class="form-label1">
                            Atesto Chek-List acima devidamente preenchido e assino o presente.<br><br>
                            Responsável: ..........................................................<br><br>
                            Cliente: ...................................................................<br><br> 
                            <span class="form-required">Cliente acompanhou e assinou o Chek-List concordando, insentando a Mecânica Tibolla de qualquer coisa que por ventura venha a ser visto posteriormente.</span>
                        </label>
                        <div class="form-input2">
                            <input type="checkbox" name="concordo" ><label class="type-of-test"></label>
                        </div>
                    </li>
                <input type="submit" name="cadastrar" value="Gravar Chek-List">
                </ul>
            </form>
        </div>
    </div>
</div>

    
asked by anonymous 13.11.2017 / 01:26

1 answer

0

Well on your form your <form> tag should look this way

<form action='grava_ckecklist.php' method='POST'>

And your inputs must have identical names to match your POSTS, since the $_POST is nothing more than a variable that receives the data from the form and then stores it in a variable to insert into the database. Make sure your inputs are like this, as in the example below.

<input type='text' name='responsavel'>
<input type='text' name='placa'>
<input type='text' name='veiculo'>

And in order for your POST to match and receive the data from the form, it must be identical to the names of your inputs , as in the example below.

$responsavel = $_POST['responsavel'];
$placa = $_POST['placa'];
$veiculo = $_POST['veiculo'];

And now we go to INSERT , I did a test here and it worked right with your INSERT , so I'll put it down too

$result_cadastro = "INSERT INTO cadastro (responsavel, placa, veiculo, cor, 
combustivel, pneus, kilometragem, paradiante, teto, traseira, paratraseiro, 
paralamad, paralamae, portam, portac, ptrasd, ptrase, parabrisa, dia, mes, 
ano, nome_cliente, sobrenome, telefone, bairro, cidade, documento, email, 
observacao) VALUES ('$responsavel', '$placa', '$veiculo', '$cor', 
'$combustivel', '$pneus', '$kilometragem', '$paradiante', '$teto', 
'$traseira', '$paratraseiro', '$paralamad', '$paralamae', '$portam', 
'$portac', '$ptrasd', '$ptrase', '$parabrisa', '$dia', '$mes', '$ano', 
'$nome_cliente', '$sobrenome', '$telefone', '$bairro', '$cidade', 
'$documento', '$email', '$observacao')"; 

So check the size you put of your fields in your database, because if you indicated by an example that the responsavel field in the cadastro table will be varchar(20) , that is, it will receive up to 20 characters in the database. maximum, and you are trying to enter data coming from the form with only 21 characters in this field and the others are all correct, INSERT will not work, so check the size of your fields in Banco de Dados and do what I will indicate below in your <input>

If the field has a character limitation, as I will show in the example below

responsavel varchar(20)

Add this to your input, as it will cause the field to only receive a maximum of 20 characters, making it impossible to write errors from the form

<input type='text' name='responsavel' maxlength='20'> 

If you still can not get the expected result that is your INSERT in Banco de Dados do this that I will show you below, after your variable $resultado_cadastro of a echo in the variable of your INSERT as I will show below

$resultado_cadastro = mysqli_query($conn, $result_cadastro);
echo $result_cadastro;

This will display the data coming from the form on the screen and you can check more clearly where the error is, and if not see copy the result displayed on the screen and paste in your database and then there will show you the error, if you are inserting data of caracter em campo inteiro , data of caracter em campo booleano . And then you give feedback here in my response to and tell me what is happening after that everything we will solve.

    
13.11.2017 / 03:45