Insert data into database

Asked

Viewed 78 times

1

How could I insert the data from the image below into the database I created . is not giving and I only entered this 0. inserir a descrição da imagem aqui

that’s the code

  <html>
    <body>
    <head>
           <meta charset="UTF-8">
            <title>Sistema de  Inventário</title>

            <style>
         html { 
             font: 13px Arial, sans-serif; 
             width: 100%; 

             margin-top: 5%; 
         } 
         label { 
             display: block; 
             clear: both; 
             width: 200px; 
             color: black; 
             font-size: 18px; 
         } 

         input { 
             border: 1px solid #E6E6FA;
             padding-left: 5px; 
         } 

         input[type="submit"],input[type="reset"] { 
             width: 100px; 
             height: 30px; 
             background: #32CD32; 
             color: white; 
             margin-left: 10px; 
         } 
        fieldset{ 
             border: 1px solid #E6E6FA; 
             color: black; 
             font-size: 20px; 

         } 
       .form_inp { 
             float: center; 
             margin-top: 17px; 
             height: 30px;
             width:  18px 
             clear: both; 
         }

         hr {
            border: 1px solid #E6E6FA; 
         }

            </style>


    <title>Sistema deInventário</title>
    <style>
         html { 
             font: 13px Arial, sans-serif; 
             width: 990px; 
             margin-left: 10%;
             margin-top: 5%; 
         } 

         .blue { 
              color: #0000FF;
              font-size: 14px;
              font-family: verdana;
         } 

         .red { 
              color: red; 
              font-size: 14px;
              font-family: verdana;
         } 

         label { 
             display: block; 
             clear: both; 
             width: 200px; 
             color: black; 
             font-size: 13px; 
         } 

         input { 
             border: 1px solid #E6E6FA;
             padding-left: 5px; 
         } 

         input[type="submit"],input[type="reset"] { 
             width: 100px; 
             height: 30px; 
             background: #32CD32; 
             color: white; 
             margin-left: 10px; 
         } 

         fieldset{ 
             border: 1px solid #E6E6FA; 
             color: black; 
             font-size: 20px; 
         } 

         .form_inp { 
             float: right; 
             margin-top: -17px; 
             height: 13px;
             clear: both; 
         }

         hr {
            border: 1px solid #E6E6FA; 
         }
    </style>





    <form method="post" action="cadastrando.php" onSubmit="">
        <fieldset>
            <legend>Sistema de Inventário</legend><br />

            <label class="borda">Setor: </label>
            <input class="form_inp" type="text" name="setor" size="30" required><br />

            <label class="borda">Usuário:</label>
            <input class="form_inp" type="text" id="usuario" name="usuario" size="30" required><br />

            <label class="borda">O/S :</label>
            <input class="form_inp" type="text" name="os" size="30" required><br /><br />

            <label class="borda">Hd : </label>
            <input  class="form_inp"type="text"  name="hd" size="30" required><br />                        
            <hr />          
            <label class="borda">Memória:</label>
            <input class="form_inp" type="text" id="" name="memoria" size="30" required><br />

            <label class="borda">Processador: </label>
            <input class="form_inp" type="text" id="processador"  name="processador" size="30" required><br /><br />
            <hr />
            <label class="borda">Cd/Dvd: </label>
            <select class="form_inp"  name="cd"> 
                <option value="Sim">Sim</option> 
                <option value="Não">Não</option> 
            </select>

            <br />

            <label class="borda">Placa Mãe: </label>
            <input class="form_inp" type="text" id="placam" name="placam" size="30" required><br />

            <label class="borda">HostName: </label>
            <input class="form_inp"type="text" id="host" name="host" size="30" required><br /><br />

            <label class="borda">Monitor/Patrimônio/Marca/Modelo: </label>
            <input class="form_inp" type="text" id="monitor" name="monitor" size="30" required><br />

            <label class="borda">Nobreak/Patrimônio/Marca/: </label>
            <input class="form_inp" type="text" id="nobreak" name="nobreak" size="30" required><br />

            <label class="borda">Placa de Rede : </label>
            <input class="form_inp" type="text" id="placar" name="placar" size="30" required><br />

            <label class="borda">Placa de Vídeo: </label>
            <input class="form_inp" type="text" id="placav" name="placav" size="30" required><br />

            <hr />
            <input type="submit" style="float: right;" value="Cadastrar" >
            <input type="reset" style="float: right;" value="Limpar">

        </fieldset>
    </form>

    <?php
        if($_SERVER['REQUEST_METHOD'] == 'POST') {
        print_r($_POST);
        $setor=$_POST['setor'];
        $usuario=$_POST['usuario'];
        $hd=$_POST['hd'];
        $memoria=$_POST['memoria'];
        $processador=$_POST['processador'];
        $cd=$_POST['cd'];
        $placam=$_POST['placam'];
        $host=$_POST['host'];
        $monitor=$_POST['monitor'];
        $nobreak=$_POST['nobreak'];
        $placar=$_POST['placar'];
        $placav=$_POST['placav'];
        $sql="INSERT INTO setor(setor,usuario,hd,memoria,processador,cd,placam,host,monitor,nobreak,placar,placav) VALUES('$setor','$usuario','$hd','$memoria','$processador','$cd','$placam','$host','$monitor','$nobreak','$nobreak','$placav')";
        $resultado_cadastro = mysqli_query($link,$sql);
    }

        ?>
    </head>
</body>
</html>

and this other

<html>
   <head><title>Cadastrando...</title></head>
    <body>

   <?php

session_start();
    $servidor = "localhost";
    $usuario = "root";
    $senha = "";
    $dbname = "cadastro";

    //Criar a conexao

        error_reporting(0);
    $link = new mysqli ("localhost", "root", "", "cadastro");
     if($link->connect_errno){
         echo"Nossas falhas local experiência ..";
         exit();
     }  

?>
    </body>
</html>
  • The part you’re inserting into? html you don’t need if you’re receiving it (do print_r($_POST));, as I tell you in the other answer. But we need to see the php part that receives/inserts the data in the BD

  • Does your html only have CSS? Put the part showing the form you’re using to send this information to the server

  • I already put the code

  • Wait... Allan your connection should be on the same page where you try to insert (database requests), if not the variable $link there is no

  • As @Miguel said, if you are processing the data on two different pages, the connections should be made on both, on page 1 you create the HTML form, and then on page 2 you can put all the PHP code to receive and process this data

  • How could I do that has how to put as an answer

Show 1 more comment

1 answer

0


From what I understand your connection is not on the same page, nor does it matter, where you try to enter the data, try the following, and see if there is an error:

...
<?php
error_reporting(-1);
ini_set('display_errors', 'On');

//Criar a conexao
$link = new mysqli ("localhost", "root", "", "cadastro");
if($link->connect_errno){
     echo"Nossas falhas local experiência ..";
     exit();
}

if($_SERVER['REQUEST_METHOD'] == 'POST') {
        $setor=$_POST['setor'];
        $usuario=$_POST['usuario'];
        $hd=$_POST['hd'];
        $memoria=$_POST['memoria'];
        $processador=$_POST['processador'];
        $cd=$_POST['cd'];
        $placam=$_POST['placam'];
        $host=$_POST['host'];
        $monitor=$_POST['monitor'];
        $nobreak=$_POST['nobreak'];
        $placar=$_POST['placar'];
        $placav=$_POST['placav'];
        $sql="INSERT INTO setor(setor,usuario,hd,memoria,processador,cd,placam,host,monitor,nobreak,placar,placav) VALUES('$setor','$usuario','$hd','$memoria','$processador','$cd','$placam','$host','$monitor','$nobreak','$nobreak','$placav')";
        $resultado_cadastro = mysqli_query($link,$sql);
}

NOTE: You also had the error_reporting(0), so you don’t see useful error messages when you’re developing, put what I put on top and see what comes

  • then everything on one page is just

  • Yes @allanaraujo or in the files you will use the database do at the top of the file, include('conexao.php'), and in this file you have the connection, where you define your $link. That’s all you have before the if(.. of my answer put in a file apart

Browser other questions tagged

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