Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 致命错误:[]操作员不在一个页面上工作,但在另一个页面上工作_Php_Html_Mysql - Fatal编程技术网

Php 致命错误:[]操作员不在一个页面上工作,但在另一个页面上工作

Php 致命错误:[]操作员不在一个页面上工作,但在另一个页面上工作,php,html,mysql,Php,Html,Mysql,我的代码显示我收到以下错误:致命错误:[]中的字符串不支持运算符 问题是,我在“成员”页面上使用了相同的代码,但当我在“相册”页面上包含该代码时,会出现错误。PHP: $sql = "SELECT *, song_genres.genre FROM favoriteband JOIN song_genres ON favoriteband.band_name = song_genres.band_name WHERE favoriteband.username = '$username'"; $

我的代码显示我收到以下错误:
致命错误:[]中的字符串不支持运算符

问题是,我在“成员”页面上使用了相同的代码,但当我在“相册”页面上包含该代码时,会出现错误。PHP:

$sql = "SELECT *, song_genres.genre FROM favoriteband JOIN song_genres ON favoriteband.band_name = song_genres.band_name WHERE favoriteband.username = '$username'";
$query = mysqli_query($conn, $sql); #query

# If user has not favorited bands
$rows_returned = mysqli_num_rows($query);

if ($rows_returned < 1) { ?>

    <tr>
        <th>For Recommendations,<br> Start Liking Bands</th>
    </tr>

<?php } else {

# Loop through each song
while ($row = mysqli_fetch_array($query)){
    $username = $row['username'];               # Loop Username
    $band_name[] = $row['band_name'];       # Get the Band Name
    $genre[] = $row['genre'];               # Get the Genres for each band
}

// The error is fond on $band_name[] = $row['band_name'];
// Also $rows_returned shows 77 rows, so it does produce multiple values.
$sql=“SELECT*,来自favoriteband的song_genres.genre加入favoriteband.band_name=song_genres.band_name,其中favoriteband.username='$username';
$query=mysqli\u query($conn,$sql)#查询
#如果用户没有喜欢的波段
$rows\u returned=mysqli\u num\u rows($query);
如果($rows_返回值<1){?>
对于建议,
开始喜欢乐队 我的建议
它在会员页面上有效,但在相册页面上无效。这让我很困惑,因为如果它只起一次作用,那么它应该总是起同样的作用

$band_name = $row['band_name']; //works
$genre = $row['genre'];   //works
如果将字符串视为数组,则会出现致命错误:

$bandname[] = 'string'; // fatal error
只需在开头添加此项即可修复该错误

$band_name = array();
$genre = array();

你需要声明$band_name=array();和$genre=array();它起作用了!谢谢。但根本的问题是,在没有我调用
$band_name=array();
的情况下,它是如何在一个页面上起作用的,而不是在另一个页面上。这对我来说似乎很奇怪。
$band_name = array();
$genre = array();