N
N
Name_232022-02-03 18:49:49
PHP
Name_23, 2022-02-03 18:49:49

Can't query MySQL database?

Good afternoon, faced such problem. I am using the mysqli_qeury function, but it does not see the variable assigned to the database connection function. The connection to the database itself works, but the request does not go.
Code from dbconect.php

<?php

// Подключение к БД
$myHostName = "localhost";
$myUserName = "root";
$myPassword  = "";
$myDataBase = "";

$dbconnect = mysqli_connect($myHostName,$myUserName,$myPassword,$myDataBase);

// Проверка подключения к БД
if ($dbconnect == true) {
    echo  "<pre>";
    echo "Успешное подключение к БД";
    echo  "<pre>";
}
else{
    echo  "<pre>";
    exit ("Ошибка подключения к БД");
    echo  "<pre>";
    mysqli_close($dbconnect);
}

?>

Code from signup.php
<?php
session_start();
require "dbconect.php";
// Данные регистрации
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$email = $_POST["email"];
$password = $_POST["password"];
$password_confirm = $_POST["password_confirm"];
$captcha = $_POST["captcha"];

// Проверка паролей и капчи
if (($password == $password_confirm) and ($captcha == $_SESSION["rand"])) {
    header("Location: ../www/form_auto.php");
} else {
    $_SESSION["msg"] = "Пароли не совпадают";
    header("Location: ../www/form_register.php");
}

mysqli_query($dbconnect, INSERT INTO `users` (`id`, `first_name`, `last_name`, `email`, `password`) VALUES (NULL, NULL, NULL, NULL, NULL));

?>

Here is what the console says
61fbfd000fd4e574797202.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-02-04
@Akela_wolf

Declare the variable as global. Variables in PHP, if I don't confuse anything, are local within the included file.
https://www.php.net/manual/en/language.variables.s...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question