G
G
Grisha Nikolsky2015-10-03 11:51:28
WordPress
Grisha Nikolsky, 2015-10-03 11:51:28

Why doesn't $_POST(Register) work?

Hello! I provide you with a block of code responsible for registration. Found a very interesting phenomenon: If I insert this block in sidebar.php (absolutely clean), then the code works. But if on a separate page-reg.php template, in which I specify its name and connect it to wordpress through the page attributes, then the forms are displayed, but the data is not sent to the database.
To cut off the answer options:
- when I put the code in the sidebar, then, of course, I change the action to sidebar.php
- # in mysqli_connect means that I just don't want to burn the data

<form name="regform" action="page-reg.php" method="post">
        <input type="text" name="nick" placeholder="Ник" required> <br>
        <input type="text" name="login" placeholder="Логин" required> <br>
        <input type="text" name="password" placeholder="Пароль" required> <br>
        <input type="text" name="r_password" placeholder="Повторите пароль" required> <br>
        <input type="submit" name="reg">
        <?php
        $db = mysqli_connect("#");

        if (isset($_POST['reg'])) {
            $nick = $_POST['nick'];
            $login = $_POST['login'];
            $password = $_POST['password'];
            $r_password = $_POST['r_password'];

            if ($password == $r_password) {
                $password = md5($password);
                //Запись всех значений в базу данных
                $query = "INSERT INTO camp_users VALUES('','$nick','$login', '$password', 'user')";
                $result = mysqli_query($db, $query);
                header("Location: index.php");

            } else {
                echo "Пароли не совпадают!";
                $hasError = true;
            }
        }


        mysqli_close($db);
        ?>

    </form>

Thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2015-10-03
@VoxelGod

Your form action is incorrect.
but editing only this part in this code will not be enough. your code is not safe. in its current form, it cannot be inserted into the working site.
if you plan to use it on a WordPress site, why not take advantage of the built-in features of the engine?
https://codex.wordpress.org/Function_Reference/wp_...
or
https://codex.wordpress.org/Function_Reference/wp_...
as a last resort, if these functions are not suitable for some reason, you can use database engine functions.
https://codex.wordpress.org/Class_Reference/en:wpd...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question