A
A
Alexbangbang2020-05-15 18:04:49
PHP
Alexbangbang, 2020-05-15 18:04:49

When entering information from a form on a site in mysql, an extra entry appears, how to remove it?

there is a submission form

<form method="post" class="form">
    <div class="pr-title">
      Добавить участок
      <span class="close" onclick="setVisibility('pre', 'none')">&times;</span>
    </div>
    <div style="text-align: center;">
      <p>
        <label>Участковая избирательная комиссия №</label>
        <input type="text" class="input1" name="id">
      </p>
      <p>
        <label>Место нахождения</label></p>
      <p>
        <input type="text" class="input2" name="name"></p>
      <p><label>Адрес</label></p>
      <p>
      <input type="text" class="input3" name="town" placeholder="город">
      <input type="text" class="input4" name="street" placeholder="улица">
      <input type="text" class="input5" name="house" placeholder="дом">
      <p><input class="subpre" name="sub" type="submit" value="Добавить"/></p>
    </div>
  </form>

there is a php input with a request
<?php

    @$id = @$_POST['id'];
    @$name = @$_POST['name'];
    @$town = @$_POST['town'];
    @$street = @$_POST['street'];
    @$house = @$_POST['house'];

    
    @$spec = mysqli_fetch_assoc(@$spec);
    

    $mysqli->query("INSERT INTO `precinct` (`id`, `name`, `town`, `street`, `house`) VALUES ('$id', '$name', '$town','$street', '$house')");

  ?>

all information is entered, but 0 also appears, although I did not enter it in any way. what could be the problem?
KyifNjiSoJs.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Gordinskiy, 2020-05-15
@DmitriyGordinskiy

I suspect that your form handler is located in the "controller" of the page with the form, and every time you open it, you write empty data, from which there was no POST request.
They get smothered by suppressing errors, and then they run to the forums for help -_-

S
SagePtr, 2020-05-15
@SagePtr

Before inserting data, they must be checked (including for non-emptiness for required fields). In your case, it is also easy to perform SQL injections.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question