Error in insert in database

0

Well I'm developing an IT inventory besides giving some error, when inserting a hd of 80 it only saves the zero and the other data are not entered as well. how can I solve this.

Thisisthecode

<formmethod="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);
}

    ?>

And another mistake to give is the following, why is giving this error if everything is right, I will be grateful.

    
asked by anonymous 22.12.2016 / 21:34

1 answer

5

By the action of your form, the php part must be inside the file cadastrando.php .

The errors later, if I'm thinking well, you can solve with a simple verification of the http method that was used to make the request inside the file cadastrando.php :

<?php
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);
}
?>

To test this you can put inside this if above the following:

...
print_r($_POST);
...

And then you see if you print the data you filled out on the form, then you know you can do what you have to do with it.

But remember that you have to declare your connection that is in the $link variable before the actual insertion in the DB, so I see you are not declaring / importing it anywhere.

Note that you can leave your php in the same form file, but you have to delete ' action="cadastrando.php" ' inside <form ... , and use the same piece of code as above

    
22.12.2016 / 21:39