我的php中有一行代码:
$sel_venue = "SELECT 'char_type' FROM 'character_type_allowed' WHERE status='Open'";
$run_venue = mysqli_query($con,$sel_venue);
while ($row = mysqli_fetch_array($run_venue))
if ($row['char_type'] == 'Mortal')
{ print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>"); }
与此相关的链接无效。除了表演之外的零互动想要扩展。我的错误日志产生了这个:为什么要求这个?
[08-Aug-2016 23:28:41 America / New_York] PHP警告:mysqli_fetch_array()期望参数1为mysqli_result,第8行的/home/houchat/public_html/incl/creation.php中给出布尔值< / p>
答案 0 :(得分:1)
您不能使用'作为字段/表名的刻度。
您的查询产生错误。您可以使用mysqli_error($ con)查看错误。
请参阅下面的更正代码
$sel_venue = "SELECT `char_type` FROM `character_type_allowed` WHERE status='Open'";
$run_venue = mysqli_query($con,$sel_venue) or die(mysqli_error($con));
while ($row = mysqli_fetch_array($run_venue)) {
if ($row['char_type'] === 'Mortal') {
print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>");
}
}
答案 1 :(得分:0)
您的查询失败,因此$run_venue
是布尔false
而不是您期望的。您应该在使用任何查询结果之前检查错误。这样做:
$run_venue = mysqli_query(...);
if(!$run_venue) die(mysqli_error($con));
... //<- we get here if the query succeeded
您将看到错误。问题是你的SQL语句将表名包装在单引号'character_type_allowed'
之间,而不是反引号(反引号位于键盘上的tab键之上)