M
M
mim1mim2020-05-11 18:38:37
PHP
mim1mim, 2020-05-11 18:38:37

Data recording not working?

Does not write user-specified data to the database.
Code: https://pastebin.com/JbqaTJhM
PS I searched for the answer in google and did not find it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AUser0, 2020-05-11
@mim1mim

The error is in the line (password1 == password2).

F
FanatPHP, 2020-05-11
@FanatPHP

This code, of course, was written by a gray mare with her left hoof. I have not seen so many errors per unit of code for a long time
Well, at least like this:

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$dbc = mysqli_connect('127.0.0.1', 'root', '', 'buy_sell_base');
mysqli_set_charset($dbc, $charset);

if(isset($_POST['submit'])){
    $username = mysqli_real_escape_string($dbc, trim($_POST['username']));
    $password1 = trim($_POST['password1']);
    $password2 = trim($_POST['password2']);

    if($username && $password1 && $password1 == $password2){
        $query = "SELECT * FROM signup WHERE username ='$username'";
        $data = mysqli_query($dbc, $query);
        if(mysqli_num_rows($data) == 0){
            $password = password_hash($password1, PASSWORD_DEFAULT);
            $query = "INSERT INTO signup (username, password) VALUES ('$username', '$password')";
            mysqli_query($dbc, $query);
            echo 'Все готово';
            exit();
        }
        else{
            echo 'Пользователь уже зарегистрирован';
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question