每当我尝试使用php连接到数据库时,我都会不断收到此错误:Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /homepages/12/d441172468/htdocs/Organizer/dashboard/index.php on line 258
如何解决此问题?我的代码是
$email = 'redacted@me.com_classes';
echo $email;
$result = mysqli_query($con,"SELECT * FROM $email");
$classcount = 1;
while($row = mysqli_fetch_array($result))
{
$period = $row['period'];
$teacher = $row['teacher'];
$subject = $row['subject'];
$subjecto = strtolower($subject);
$subjecto = str_replace(' ', '', $subjecto);
$grade = $row['grade'];
echo "<li id='button" . $classcount . "' onclick='" . $subjecto . "(),homework" . $classcount . "()'>" . $classcount . ". " . $subject . "-" . $grade . "</li>\n";
$classcount += 1;
}
当我回显它时,$email
变量工作正常。第128行是while($row = mysqli_fetch_array($result))
部分
答案 0 :(得分:1)
如果$email
的值确实是您的表名,则需要引用它,因为它包含不带引号的table names中不允许的字符(@
):
$result = mysqli_query($con,"SELECT * FROM `$email`");
请注意,您需要使用mysql中的反引号引用表名和列名。
答案 1 :(得分:0)
ASCII
:http://dev.mysql.com/doc/refman/5.1/en/identifiers.html
Permitted characters in unquoted identifiers:
ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore)
Extended: U+0080 .. U+FFFF
Permitted characters in quoted identifiers include the full Unicode Basic Multilingual Plane (BMP), except U+0000:
ASCII: U+0001 .. U+007F
Extended: U+0080 .. U+FFFF
ASCII NUL (U+0000) and supplementary characters (U+10000 and higher) are not permitted in quoted or unquoted identifiers.
Identifiers may begin with a digit but unless quoted may not consist solely of digits.
Database, table, and column names cannot end with space characters.
Before MySQL 5.1.6, database and table names cannot contain “/”, “\”, “.”, or characters that are not permitted in file names.
很奇怪,你是否已经手动添加了字符串@
的表格。我认为这不能作为表名处理?
跳过下面的
您的查询无效,请将代码更改为示例:
mysqli_query($con,"SELECT * FROM TABLE_NAME WHERE 'email' = $email");
使用表名更改TABLE_NAME
。
使用表TABLE_NAME上的列电子邮件名称更改email
。
你是mysql注入的受害者,所以不会检查entites和specialchars!
如果您的VALUE $电子邮件是TABLE_NAME,则该字符串应为限制字符!