Плзз расскажи мне об этом
Пользователь не входит в систему и выдает эту ошибку
Notice: Undefined variable: connect in C:\xampp\htdocs\stock\php_action\db_connect.php on line 10 Notice: Trying to get property of non-object in C:\xampp\htdocs\stock\php_action\db_connect.php on line 10 Successfully connected Notice: Undefined variable: connect in C:\xampp\htdocs\stock\index.php on line 26 Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\stock\index.php on line 26
Что я уже пробовал:
код db_connect-это:
<?php $db_name = "stock"; $mysql_user = "root"; $mysql_pass = ""; $server_name = "localhost"; $con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name); //check connection if($connect->connect_error) { die("Connection Failed " . $connect->connect_error); } else { echo "Successfully connected"; } ?>
и еще index.php есть:
<?php require_once 'php_action/db_connect.php'; session_start(); if (isset($_SESSION['userId'])) { header('location: http://localhost/stock/dashboard.php'); } $errors = array(); if ($_POST) { $username = $_POST['username']; $password = $_POST['password']; if (empty($username) || empty($password)) { if ($username == "") { $errors[] = "Username is required"; } if ($password == "") { $errors[] = "Password is required"; } }else { $sql = "SELECT * FROM users WHERE username == '$username'"; $result = $connect->query($sql); if($result->num_rows == 1) { $password == md5($password); // exists $mainSql = "SELECT * FROM users WHERE username == '$username' AND password == '$password'"; $mainResult = $connect->query($mainSql); if($mainResult->num_rows == 1) { $value = $mainResult->fetch_assoc(); $user_id = $value['user_id']; // set session $_SESSION['userId'] = $user_id; header('location: http://localhost/stock/dashboard.php'); }else{ $errors[] = "Incorrect username or password combination"; } }else{ $errors[] = "Username doesnot exists";