Error in the database

Asked

Viewed 115 times

0

Well I’m developing an IT inventory besides giving some error , when inserting an 80 hard drive it only saves the zero and the other data is not entered either. how can I fix this . inserir a descrição da imagem aqui inserir a descrição da imagem aqui

That is the code

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

    ?>

And another mistake that give is the following , why is giving this error if it is all right , I will be grateful. inserir a descrição da imagem aqui

1 answer

5


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

Errors later, if I’m thinking about it, you can solve with a simple check 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 print out 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 must declare your connection to the variable $link before the actual insertion in the BD, I see you are not declaring it/importing it anywhere

Note that you can leave your php in the same form file, but you must delete it 'action="cadastrando.php"' within the <form ..., and uses the same piece of code I put up

  • The errors left are not doing the data Insert . updated the code above .

  • I haven’t changed and I’ve confirmed your answer

  • You should ask another question with everything relevant to your connection and the way you are entering the data, no need to put HTML. I will try to help @allanaraujo , here it no longer makes sense and I can understand why, not to be inserting. Is there an error? You have the variable $link okay?

  • I’ll do it. and I’ll put all the code

  • @allanaraujo, html you do not need, if you are already receiving the data, do this test that I tell you above to test it. But if you see the data you filled in the form don’t put the html you don’t need

  • I already asked the question.

Show 1 more comment

Browser other questions tagged

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