如何修复PHP中的“通知:未定义变量:mysqli”错误

时间:2019-07-06 05:11:01

标签: php mysql

panel.php

    <?php
    $queryA = "SELECT * FROM user WHERE id=$_SESSION[userId]";
    $requestA = mysqli_query($mysqli, $queryA);
    echo $content;
    ?>

db.php

<?php
    $mysqli = mysqli_connect("localhost", "root", "", "crm");
    //mysqli_query($mysqli, "SET NAMES 'utf8'");
    session_start();
?>

initial.php

<?php
ob_start();
register_shutdown_function("show_template");
function show_template() {
    $content = ob_get_clean();
    include __DIR__ . "\panel.php";
}
?>

home.php

<?php
require_once "db.php";
require_once "initial.php";
?>

index.php

<?php
require_once "db.php";
if (isset($_REQUEST['user']) && isset($_REQUEST['pass'])) {
    $user = mysqli_real_escape_string($mysqli, $_REQUEST['user']);
    $pass = mysqli_real_escape_string($mysqli, $_REQUEST['pass']);
    $query = "SELECT * FROM user WHERE username='$user' AND password='$pass'";
    $result = mysqli_query($mysqli, $query);
    if (mysqli_num_rows($result) == 1) {
        $userID = mysqli_fetch_assoc($result);
        $_SESSION['userId'] = $userID['id'];
        header("location: /crm/home.php");
        exit;
    }else{`enter code here`
        echo 'error';
    }
}
?>

我的文件中有些代码有错误 而且我不知道我在做什么。 这是一个带有模板代码的网站

0 个答案:

没有答案