Answer the question
In order to leave comments, you need to log in
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 "Логин уже занят";
}
}
}
?>
<?php
require("constants.php");
$con = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME) OR DIE('Ошибка подключения к базе данных');
?>
<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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question