致命错误:未捕获的错误:在布尔上调用成员函数fetch_array()

时间:2019-12-17 11:21:08

标签: php mysql

我在输出mysql表的内容时遇到问题

  

致命错误:未捕获错误:调用成员函数fetch_array()   在C:\ xampp \ htdocs \ jworks \ admin.php:14中的bool中:堆栈跟踪:#0 {main}   在第14行的C:\ xampp \ htdocs \ jworks \ admin.php中抛出

<?php
  session_start();
  if ($_SESSION["username"] != "admin") {
    header("location: bemvindo.php");
    exit;
  }
  require_once("dbconnection.php");
  $sql = "SELECT * FROM videos WHERE username ".$_SESSION["username"];
  echo $sql;

$i=0;
$results = mysqli_query($link,$sql);

while ($row = $results->fetch_array(MYSQLI_BOTH)) {
  echo $row;
}
 ?>

dbconnection.php

<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'users');

/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 ?>

我试图重新创建表并在互联网上搜索解决方案,但我似乎无法解决它,我是编程的初学者,所以这可能是一个愚蠢的错误,谢谢您的时间

0 个答案:

没有答案