Form does not reach the database

Asked

Viewed 36 times

0

I created a form in HTML/PHP, I concluded and decided to connect the form to my database by XAMPP and everything ran without presenting any error, until then I tried to send a form and saved it in BD, however, in other attempts did not save any more information and also does not show any error message at all, which may be?

Follows the codes:

HTML:

<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <title>Fleisch Berg Co.</title>
    <link rel="stylesheet" href="css/trabalho.css">

</head>
<body>
    <header>
        <div id="cabecalho">
            <h1><img src="img/logo.png"></h1>    
        </div>
    </header>

    <nav class="menu">

        <ul>
             <li id="lmenu"><a href="index.html">Home</a></li>
             <li id="lmenu"><a href="fleisch.html">A&nbspFleish&nbspBerg&nbspCo.</a>
             <li id="lmenu"><a href="#">Lançamentos</a>
             <li id="lmenu"><a href="#">História</a>
             <li id="lmenu"><a href="#">Loja&nbspVirtual</a>
             <li id="lmenu"><a href="trabalho.html">Trabalhe&nbspconosco</a>
             <li id="lmenu"><a href="#">Contatos</a></li></li>     
        </ul>

    </nav>

    <div id="noti">
        <h3>Trabalhe conosco:</h3>

        <form method="post" id="jobform" action="jobs.php">
           <fieldset id="job"><legend>Identificação pessoal</legend>

           <p>Nome completo: <input type="text" name="tnome" id="cnome" size="25" maxlength="25" placeholder="Digite seu nome" required></p>
           <p>Data de nascimento: <input type="date" name="tidade" id="cidade" required></p>
           <p>Telefone: <input type="text" name="ttel" id="ctel" size="7" maxlength="7" placeholder="Seu telefone aqui" required></p>
           <fieldset id="gene"><legend>Gênero</legend>
                <input type="radio" name="tsexo" id="cmasc" required value="homem">  
                <label for="cmasc">Masculino</label><br/>
                <input type="radio" name="tsexo" id="cfem" required value="mulher">
                <label for="cfem">Feminino</label>
           </fieldset>
           <p>Endereço: <input type="text" name="tend" id="cend" size="35" maxlength="35" placeholder="Endereço aqui" required></p>
           <p><label for="cesc">Grau de escolaridade:</label></p>
           <textarea name="tesc" id="cesc" cols="40" rows="10" placeholder="Escreva seus cursos aqui" required=""></textarea>
           <p><label for="cexp">Experiência profissional:</label></p>
           <textarea name="texp" id="cexp" cols="45" rows="10" placeholder="Fala aqui as suas experiências profissíonais" required=""></textarea>
           <p><label for="csobre">Fala um pouco sobre você:</label></p>
           <textarea name="tsobre" id="csobre" cols="45" rows="10" placeholder="Fala um pouco sobre você aqui" required=""></textarea>
           <p><label for="cvaga" required>Vaga desejada:</label>
            <select name="tvaga" id="cvagas" required="">
                <option selected>Escolha a vaga</option>
                <option>Diretor</option>
                <option>Encarregado</option>
                <option>Guarda</option>
                <option>Secretária</option>
                <option>Ajudante Geral</option>
                <option>Caminhoneiro (Fixo)</option>
                <option>Caminhoneiro (Temporário)</option>
            </select>
           </fieldset>

            <P>
                <INPUT type="reset"  name="tres" value="Limpar">
                <INPUT type="submit" name="tenv" value="Enviar">
            </P>

        </form>


    </div>

    <footer>
        <div id="rodape">
            <img id="icone" src="img/icone.png">
            <p id="copy">© Copyright 2000-2018 Fleisch Berg Company S.A.</p>
        </div>
    </footer>
</body>
</html>

PHP (Form):

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>Fleisch Berg Co.</title>
  <link rel="stylesheet" href="css/trabalho.css">
</head>

<body>
  <?php


            include_once ('connection/conexao.php');
            $nome = $_POST['tnome'];
            $nasc = $_POST['tidade'];
            $tel = $_POST['ttel'];
            $gen = $_POST['tsexo'];
            $end = $_POST['tend'];
            $esco = $_POST['tesc'];
            $exp = $_POST['texp'];
            $sobre = $_POST['tsobre'];
            $vaga = $_POST['tvaga'];

            $formulariojobs = "INSERT INTO formjobs (nome, nasc, tel, gen, ende, esco, exp, sobre, vaga) VALUES ('$nome', '$nasc', '$tel', '$gen', '$end', '$esco', '$exp', '$sobre', '$vaga', NOW())";
            $resultado_msg_contato = mysqli_query($conn, $formulariojobs);




        ?>
    <a href="trabalho.html">Voltar</a>
</body>

</html>

PHP (CONNECTION):

<?php 
    $servidor = "localhost";
    $usuario = "root";
    $senha = "";
    $dbname = "jobs";

    //criar a conexão

    $conn = mysqli_connect($servidor, $usuario, $senha, $dbname);


?>
  • What are the fields and field types in the table? Note the primary key if you are auto-incrementing the new posts. Put "echo" to display the data on the screen when posting, the error may be before you reach the bank, in which case you will see the data that the page displays.

1 answer

3


You are specifying 9 fields to receive the information, but you send 10 information:

$formulariojobs = "INSERT INTO formjobs (nome, nasc, tel, gen, ende, esco, exp, sobre, vaga) VALUES ('$nome', '$nasc', '$tel', '$gen', '$end', '$esco', '$exp', '$sobre', '$vaga', NOW())";

You’re sending:

  1. '$name'
  2. '$born'
  3. '$tel'
  4. '$gen'
  5. '$end'
  6. '$Cluster'
  7. '$Exp'
  8. '$about'
  9. '$vacancy'
  10. NOW()

But you assign these values only to:

  1. name
  2. born
  3. tel
  4. gen
  5. Nde
  6. Cluster
  7. Exp
  8. about
  9. vacancy

You need to have the same number of assignments and parameters.


@Edit

To fix your other problem, follow the following procedure:

  1. Create a new field in your table of the whole type. You can name it however you want, but I will call id
  2. Set this new field with "auto increment" (auto increment) and as primary key (Primary key)
  3. Save and try again to enter records in the database.
  • I managed to make the connection with my bank, however, now only saves only 1 information and then back to stop saving, know what can be?

  • What do you mean you only save one piece of information? You only save one of the variables?

  • No, I answered the whole form and it was straight, all variable, but if I reply the form again does not send anything to the BD, remains only one.

  • That would be an answer to another question, but I will edit my answer with what you want

Browser other questions tagged

You are not signed in. Login or sign up in order to post.