F
F
fateseekers2018-04-06 01:20:22
PHP
fateseekers, 2018-04-06 01:20:22

Why is the data not showing up in the database?

I created a form and code according to the guide, or I’m a curve or something else (. It connects to the database exactly, the data is correct.
Here is the php code:

<?php 
  require ("connection.php"); 

  if(isset($_POST['submit'])){
    $login = mysqli_real_escape_string($con, trim($_POST['login']));
    $password = mysqli_real_escape_string($con, trim($_POST['password']));
    if (!empty($login) && !empty($password)) {
      $query = "SELECT * FROM `users` WHERE login = '$login'";
      $data = mysqli_query($con, $query);
      if (mysqli_num_rows($data) == 0) {
        $query = "INSERT INTO `users` (login, password) VALUES ('$login', md5('$password'))";
        mysqli_query($con, $query);
        echo "Аккаунт создан";
        mysqli_close($con);
        exit();
      } else {
        echo "Логин уже занят";
      }
    }
  }
?>

connection.php:
<?php
  require("constants.php");
  $con = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME) OR DIE('Ошибка подключения к базе данных');
?>

Well, the form itself, of course:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <div class="d-flex align-items-center justify-content-center flex-column flex-sm-row">
      <div class="flex-column">
        <div class="flex-row">
          <label for="login">Логин:  </label>
          <input type="text" name="login">
        </div>
        <div class="flex-row">
          <label for="password">Пароль: </label>
          <input type="password" name="password">
        </div>
      </div>
    <button type="submit" name="submit" class="btn"></button>
  </div>
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
Quark_rgb, 2018-04-06
@fateseekers

isset($_POST['submit'])Yes
, but there is no name="submit" in the button

<button type="submit" name="submit" class="btn"></button>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question