获取错误警告:mysqli :: query():无法在我的代码中获取mysqli

时间:2017-07-08 07:37:13

标签: php mysqli

获取错误警告:mysqli :: query():无法在

中获取mysqli
  <?php

    include 'includes/config.php';
    include 'includes/database.php';
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);



    if (isset($_POST['sign'])) {
      $name=$_POST['email'];
      $pass=$_POST['password'];
      $query_two="SELECT * FROM admin WHERE user='$name' AND password='$pass' ";
      $runn=$db->query($query_two);

      $row_login=$runn->fetch_assoc();

    if ($row_login['user']==$name && $row_login['password']==$pass) {
      session_start();

      $_SESSION["username"] = $name;
      header('Location: adminpane.php');
      exit();

    }

    else {
      echo "<script>
    check();

      </script>

      ";
      exit();


    }


    }


     ?>
  

这是我的database.php文件

<?php
$db=new mysqli(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME);
?>
  

这是在我的config.php文件中

 <?php

define('DB_HOST', 'xxx.xxx.xxx.xxx');
define('DB_USERNAME', 'XXX');
define('DB_PASSWORD', 'XXX');
define('DB_NAME', 'myDB');


 ?>
  

我在顶部包括两个,但它似乎仍然没有工作!!,   一切用户名密码都是正确的,代码正在进行中   当地主人

1 个答案:

答案 0 :(得分:0)

使用以下内容:

<?php 
session_start();
include 'includes/config.php';
include 'includes/database.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

if (isset($_POST['sign'])) {
  $name = mysqli_real_escape_string($db,$_POST['email']);
  $pass = mysqli_real_escape_string($db,$_POST['password']);
  $query_two = "SELECT * FROM admin WHERE user='$name' AND password='$pass'";
  $runn = mysqli_query($db,$query_two);
  $row_login = mysqli_fetch_assoc($runn);

  if ($row_login['user']==$name && $row_login['password']==$pass) {
   $_SESSION["username"] = $name;
   header('Location: adminpane.php');
   exit();
  } else {
   echo "<script>check();</script>";
   exit();
 }
}
?>