Save form in database

Asked

Viewed 87 times

1

I created a system in which there is a form that I want to save in the database and display it in another screen that I am developing but I do not know how to save the form although it receives the values(are not empty) it is not saved in the database.

Form

<?php

?>
<!DOCTYPE html>
<html lang="pt-br">

<head>
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

    <head>

    <body onload="load()" onunload="erase()" method="POST"action="salva_mensagem.php">
        <label style="margin-left:650px;margin-top: 50px;font-size: 25px;">Selecione o Serviço</label>
        <div style="text-align: center; margin-top: 30px; align-items: center;">
            <div style="padding-bottom: 20px;">
                <button name="btnacomp" type="button" onclick="mostracomp('acompanhamentoss')" style="background-color:#2c868f;margin: 0px 0px 15px;padding: 10px 60px;font-size: 18px; border-radius:10%"><a>Acompanhamentos</a></button>
                <button name="btnaud" type="button" onclick="mostraaud('audienciass')" style="background-color: #2c868f;font-size: 18px;margin: 0px 0px 15px;padding: 10px 90px;border-radius:10%"><a>Audiências</a></button>
            </div>
            <div style="padding-bottom: 20px;">
                <button name="btncopia" type="button" onclick="mostracopia('copiass')" style="background-color: #2c868f;margin: 0px 0px 15px;padding: 10px 110px;font-size: 18px;border-radius:10%"><a>Cópias</a></button>
                <button name="btndist" type="button" onclick="mostradist('distribuicaoo')" style="background-color: #2c868f;font-size: 18px;margin: 0px 0px 15px;padding: 10px 90px;border-radius:10%"><a>Distribuição</a></button>
            </div>
            <div style="padding-bottom: 20px;">
                <button name="btnprot" type="button" onclick="mostraprot('protocoloss')" style="background-color: #2c868f;margin: 0px 0px 15px;padding: 10px 95px;font-size: 18px;border-radius:10%"><a>Protocolos</a></button>
                <button name="btnoutroser" type="button" onclick="mostraoutroser('outros')" style="background-color: #2c868f;font-size: 18px;margin: 0px 0px 15px;padding: 10px 75px;border-radius:10%"><a>Outros Serviços</a></button>
            </div>
        </div>
        <form method="POST" action="salva_mensagem.php">
            <div style="text-align: center;">

                <div id="outros" method="POST" action="salva_mensagem.php" style="display: none;">
                    <label style="font-size: 18px;">Tipo de Serviço:</label><br>
                    <select name="tiposervico">
                        <option value="">Selecione</option>
                        <option value="alvaras">Alvarás</option>
                        <option value="analises">Análises</option>
                        <option value="andamentos">Andamentos</option>
                        <option value="buscas">Buscas e Apreensões</option>
                        <option value="cargas">Cargas</option>
                        <option value="certidoes">Certidões</option>
                        <option value="despachos">Despachos</option>
                        <option value="pecas">Elaboração de Peças</option>
                        <option value="tese">Elaboração de Tese</option>
                        <option value="exame">Exame de Processos</option>
                        <option value="guias">Guias</option>
                        <option value="mandados">Mandados</option>
                        <option value="sustentacoes">Sustentações Orais</option>
                        <option value="outros">Outros Serviços</option>
                    </select>
                </div><br>

                <div id="acompanhamentoss" style="display:none; margin:auto; width: 60%;margin-left: 300px; text-align: left;">
                    <div method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Local do Serviço:</label><br>
                        <input type="text" name="localservico" size="40px">
                    </div><br>

                    <div id="acompanhamentoss" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Prazo Limite:</label><br>
                        <input type="text" name="prazoaud" placeholder="Data ">
                        <input type="text" name="prazohoraaud" placeholder="Hora">
                    </div><br>
                    <div id="acompanhamentoss">
                        <label style="font-size: 18px;">Profissional com Certificado Digital?</label><br>
                        <select name="proccertdig">
                            <option value="">Selecione</option>
                            <option value="sim">Sim</option>
                            <option value="nao">Indiferente</option>
                        </select>
                    </div><br>
                    <div id="acompanhamentoss">
                        <label style="font-size: 18px;"> Tipo de Processo:</label><br>
                        <select name="tipoproc">
                            <option value="">Selecione</option>
                            <option value="digital">Digital</option>
                            <option value="fisico">Físico</option>
                        </select>
                    </div><br>
                    <div id="acompanhamentoss">
                        <label style="font-size: 18px;">Numero do Processo:</label><br>
                        <input type="text" name="numproc">
                    </div>



                </div><br>
                <div id="audienciass" style="display:none; width: 60%;margin-left: 300px;text-align: left;">
                    <div id="audienciass" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Área:</label><br>
                        <select name="area">
                            <option value="">Selecione</option>
                            <option value="trabalhista">Trabalhista</option>
                            <option value="civel">Cível</option>
                            <option value="criminal">Criminal</option>
                            <option value="outra">Outra</option>
                        </select>
                    </div><br>
                    <div id="audienciass" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Tipo de Audiência:</label><br>
                        <select name="tipoaud">
                            <option value="">Selecione</option>
                            <option value="conciliacao">Conciliação</option>
                            <option value="julgamento">Julgamento</option>
                            <option value="instrucao">Instrução</option>
                            <option value="instr_julg">Instrução e Julgamento</option>
                            <option value="una">Una</option>
                            <option value="outro">Outro</option>
                        </select>
                    </div><br>
                    <div id="audienciass" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Local do Serviço:</label><br>
                        <input type="text" name="localservico" size="40px">
                    </div><br>
                    <div id="audienciass">
                        <label style="font-size: 18px;">Data da Audiência:</label><br>
                        <input type="text" name="dataaud" placeholder="Data">
                        <input type="text" name="horaaud" placeholder="Hora">
                    </div><br>
                    <div id="audienciass">
                        <label style="font-size: 18px;">Tipo de Profissional Necessario: </label><br>
                        <select name="tipoprocnec">
                            <option value="">Selecione</option>
                            <option value="advogado e preposto">Advogado e Preposto</option>
                            <option value="somente advogado">Somente Advogado</option>
                            <option value="somente preposto">Somente Preposto</option>
                        </select>
                    </div><br>
                    <div id="audienciass">
                        <label style="font-size: 18px;"> Profissional com Certificado Digital?</label><br>
                        <select name="proccertdig">
                            <option value="">Selecione</option>
                            <option value="sim">Sim</option>
                            <option value="nao">Indiferente</option>
                        </select>
                    </div><br>
                    <div id="audienciass">
                        <label style="font-size: 18px;">Tipo de Processo:</label><br>
                        <select name="tipoproc">
                            <option value="">Selecione</option>
                            <option value="digital">Digital</option>
                            <option value="fisico">Físico</option>
                        </select>
                    </div><br>
                    <div id="audienciass">
                        <label style="font-size: 18px;">Numero do Processo:</label><br>
                        <input type="text" name="numproc">
                    </div>



                </div><br>
                <div id="distribuicaoo" style="display:none; width: 60%;margin-left: 300px;text-align: left;">
                    <div method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Local do Serviço:</label><br>
                        <input type="text" name="localservico" size="40px">
                    </div><br>
                    <div id="distribuicaoo" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Prazo Limite:</label><br>
                        <input type="text" name="prazoaud" placeholder="Data ">
                        <input type="text" name="prazohoraaud" placeholder="Hora">
                    </div><br>
                    <div id="distribuicaoo">
                        <label style="font-size: 18px;">Profissional com Certificado Digital?</label><br>
                        <select name="proccertdig">
                            <option value="">Selecione</option>
                            <option value="sim">Sim</option>
                            <option value="nao">Indiferente</option>
                        </select>
                    </div><br>
                    <div id="distribuicaoo">
                        <label style="font-size: 18px;">Tipo de Processo:</label><br>
                        <select name="tipoproc">
                            <option value="">Selecione</option>
                            <option value="digital">Digital</option>
                            <option value="fisico">Físico</option>
                        </select>
                    </div><br>
                    <div id="distribuicaoo">
                        <label style="font-size: 18px;">Numero do Processo:</label><br>
                        <input type="text" name="numproc">
                    </div>





                </div><br>
                <div id="protocoloss" style="display:none; width: 60%;margin-left: 300px;text-align: left;">
                    <div method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Local do Serviço:</label><br>
                        <input type="text" name="localservico" size="40px">
                    </div><br>
                    <div id="protocoloss" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Prazo Limite:</label><br>
                        <input type="text" name="prazoaud" placeholder="Data ">
                        <input type="text" name="prazohoraaud" placeholder="Hora">
                    </div><br>
                    <div id="protocoloss">
                        <label style="font-size: 18px;">Profissional com Certificado Digital?</label><br>
                        <select name="proccertdig">
                            <option value="">Selecione</option>
                            <option value="sim">Sim</option>
                            <option value="nao">Indiferente</option>
                        </select>
                    </div><br>
                    <div id="protocoloss">
                        <label style="font-size: 18px;">Tipo de Processo:</label><br>
                        <select name="tipoproc">
                            <option value="">Selecione</option>
                            <option value="digital">Digital</option>
                            <option value="fisico">Físico</option>
                        </select>
                    </div><br>
                    <div id="protocoloss">
                        <label style="font-size: 18px;">Numero do Processo:</label><br>
                        <input type="text" name="numproc">
                    </div>
                </div><br>

                <div id="copiass" style="display: none; width: 60%;margin-left: 300px;text-align: left; ">
                    <div method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Local do Serviço:</label><br>
                        <input type="text" name="localservico" size="40px">
                    </div><br>
                    <div>
                        <label style="font-size: 18px;">Profissional com Certificado Digital?</label><br>
                        <select name="proccertdig">
                            <option value="">Selecione</option>
                            <option value="sim">Sim</option>
                            <option value="nao">Indiferente</option>
                        </select>
                    </div><br>
                    <div>
                        <label style="font-size: 18px;">Tipo de Processo:</label><br>
                        <select name="tipoproc">
                            <option value="">Selecione</option>
                            <option value="digital">Digital</option>
                            <option value="fisico">Físico</option>
                        </select>
                    </div><br>
                    <div id="copiass" method="POST" action="paineldemanda.html">
                        <label v>Tipo da Cópia:</label><br>
                        <select name="tipocopia">
                            <option value="">Selecione</option>
                            <option value="despacho">Despacho do Juiz</option>
                            <option value="embargos">Embargos de Execução</option>
                            <option value="inicial">Inicial de Processo</option>
                            <option value="parcial">Parcial</option>
                            <option value="processo">Processo Integral</option>
                            <option value="recursos">Recursos</option>
                            <option value="ultimos">Últimos Andamentos</option>
                        </select>
                    </div><br>

                    <div id="copiass" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Quandidade de Cópias:</label><br>
                        <input type="text" name="quantcop">
                    </div><br>
                    <div id="copiass" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Formato das Cópias:</label><br>
                        <select name="formcop">
                            <option value="">Selecione</option>
                            <option value="legivel">Foto Legível</option>
                            <option value="impresso">Impresso</option>
                            <option value="pdf">Digitalizado em PDF</option>
                        </select>
                    </div><br>
                    <div id="copiass" method="POST" action="paineldemanda.html">
                        <label v>Reembolsa custo das Cópias:</label><br>
                        <select name="custocop">
                            <option value="">Selecione</option>
                            <option value="sim">Sim</option>
                            <option value="nao">Não</option>
                        </select>
                    </div><br>
                    <div id="copiass" method="POST" action="paineldemanda.html">
                        <label style="font-size: 18px;">Prazo Limite:</label><br>
                        <input type="text" name="prazoaud" placeholder="Data ">
                        <input type="text" name="prazohoraaud" placeholder="Hora">
                    </div><br>

                    <div id="copiass">
                        <label style="font-size: 18px;">Numero do Processo:</label><br>
                        <input type="text" name="numproc">
                    </div>
                </div><br>
                <!--Contato -->
                <div onload="save()" onunload="save()" action="salva_mensagem.php" method="POST" >
                    <label style="font-size: 22px;"><strong>Informações de Contato</strong></label><br><br>
                    <label style="font-size: 18px;" >Nome:</label><br>
                    <input  name="nome" placeholder="Nome Completo" size="40px" action="salva_mensagem.php" method="POST" required></br></br>

                    <label style="font-size: 18px;">Email:</label><br>
                    <input  name="email" placeholder="Seu melho e-mail" size="40px" action="salva_mensagem.php" method="POST" required></br></br>

                    <label style="font-size: 18px;">Telefone:</label><br>
                    <input  name="fone" placeholder="Telefone de Contato" size="40px"action="salva_mensagem.php" method="POST" required></br></br>

                    <label style="font-size: 18px;">Mensagem:</label><br>
                    <textarea name="mensagem" style="padding: 5%;" action="salva_mensagem.php" method="POST" ></textarea></br></br>
                </div>
                <input type="submit"  value="Enviar Demandas" onclick="btnenviardemanda()">



            </div>




        </form>

    </body>
    <script>
        function mostracopia(el) {
            var display = document.getElementById(el).style.display;
            var mostracomp = document.getElementById(el).style.display;
            if (display == "none")
                document.getElementById(el).style.display = 'block';
            else
                document.getElementById(el).style.display = 'none';
        }

        function mostracomp(el) {
            var display = document.getElementById(el).style.display;
            if (display == "block")
                document.getElementById(el).style.display = 'none';
            else
                document.getElementById(el).style.display = 'block';
        }

        function mostraaud(el) {
            var display = document.getElementById(el).style.display;
            if (display == "block")
                document.getElementById(el).style.display = 'none';
            else
                document.getElementById(el).style.display = 'block';
        }

        function mostradist(el) {
            var display = document.getElementById(el).style.display;
            if (display == "block")
                document.getElementById(el).style.display = 'none';
            else
                document.getElementById(el).style.display = 'block';
        }

        function mostraprot(el) {
            var display = document.getElementById(el).style.display;
            if (display == "block")
                document.getElementById(el).style.display = 'none';
            else
                document.getElementById(el).style.display = 'block';
        }

        function mostraoutroser(el) {
            var display = document.getElementById(el).style.display;
            if (display == "block")
                document.getElementById(el).style.display = 'none';
            else
                document.getElementById(el).style.display = 'block';
        }

        function btnenviardemanda() {

            window.location = 'salva_mensagem.php';

            window.localStorage.setItem('nome', $('#nome').val());
            window.localStorage.setItem('email', $('#email').val());
            window.localStorage.setItem('mensagem', $('#mensagem').val());


        }

        function load() {
            $('#user_name').val(window.localStorage.getItem('nome'));
            $('#user_email').val(window.localStorage.getItem('email'));
            $('#mensag').val(window.localStorage.getItem('mensagem'));

        }

        function erase() {
            window.localStorage.removeItem('nome');
            window.localStorage.removeItem('email');
            window.localStorage.removeItem('mensagem');


        }
    </script>

</html>

Connexion.php

<?php
    $servidor= 'localhost';
    $user = 'root';
    $password = '';
    $dbName = 'formulario';
    $port = 3306;
    
    
    try{
    
    $conn = new PDO("mysql:host=$servidor;port=$port;dbname=" .$dbName, $user,$password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "<h1>Successfully Connected</h1>";
    
    }catch(PDOException $ex){
    
    
    echo "<h1>Erro ao Conectar</h1>".$ex->getMessage();
    
    }

?>

Where save the Form

<?php
session_start();

include_once './conexao.php';

$nome = filter_input(INPUT_POST,"nome",FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST,"email",FILTER_SANITIZE_STRING);
$fone = filter_input(INPUT_POST,"fone",FILTER_SANITIZE_STRING);
$mensagem = filter_input(INPUT_POST,"mensagem",FILTER_SANITIZE_STRING);

var_dump($_POST);


//Insere os dados no banco
$get_data = "INSERT INTO formteste (nome, email,fone,mensagem,created) VALUES (:nome, :email, :fone,:mensagem, NOW())";

$insert_data = $conn->prepare($get_data);
$insert_data->bindParam(':nome', $nome);
$insert_data->bindParam(':email', $email);
$insert_data->bindParam(':fone', $fone);
$insert_data->bindParam(':mensagem', $mensagem);



?>

I thank from already help of you I am new in database.

  • You just prepared SQL, but you didn’t execute it... you missed a $insert_data->execute() there.

  • Insert below $insert_data->bindParam(':message', $message);??

1 answer

1

It was only necessary to execute the code buddy.

After your last line of code...

$insert_data->bindParam(':message', $message);

Insert:

$insert_data->execute();

Browser other questions tagged

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