Y
Y
yellow_pus2021-09-08 14:19:40
PHP
yellow_pus, 2021-09-08 14:19:40

Why is mysql database query not being sent?

I wrote something like a registration window, where the user must enter a name, phone number, login, password, and these values ​​\u200b\u200bwould be sent to the database. But for all values ​​in general, the data is not sent anywhere

<?php
$conn = mysqli_connect('mysql','root','root','user');
if ($conn){
    echo'success';
} else{
    echo'not success';
}
if(isset($_POST['send'])){
            $name = $_POST['name'];
            $number = $_POST['phone'];
            $login= $_POST['login'];
            $password = $_POST['password'];
            $query = "INSERT INTO reg VALUES(NULL,$name,$number,$login,$password);";
            $r = mysqli_query($conn,$query);
}
?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href = 'style.css'>
</head>
<body>
<div class = 'registration'>
    <h1>Регистрация</h1> <h6>или <a href = 'auth.html'>Авторизация</a></h6>
    <form action="mysqliTestDb.php" method="post">
                <label>
                    <input type = 'text' required name = 'name' placeholder="Введите ваше имя" size="25"><br><br>
                    <input type = 'tel' required name = 'phone' placeholder="+7-xxx-xx-xx" size="25"><br><br>
                    <input type = 'text' required name = 'login' placeholder="Придумайте логин" size="25"><br><br>
                    <input type = 'password' required name = 'password' placeholder="Придумайте пароль" size="25"><br><br>
                    <input type="submit" name = 'send' value="Отправить">
                </label>
    </form>
</div>

</body>
</html>

Also, when trying to display sql_query (), it outputs a boolean value of false.
What could be wrong? in the code or in setting up the db columns? I am attaching a screenshot from phpmyadmin61389c449d8bd002495209.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2021-09-08
Semenov

instead of INSERT INTO reg VALUES(NULL,$name,$number,$login,$password);
try it:

INSERT INTO reg (id, name, phone, login, password) VALUES (NULL,$name,$number,$login,$password);

also do var_dump($query); after this $query = ..., in order to see what the request turned out to be and try to execute it manually through phpmyadmin, you will most likely see an error and you can understand what and how.
Another hint, in order to see how the correct query should look like, add it manually via phpmyadmin, there you will have an example of a sql query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question