我知道有很多关于调试 PHP 的内容,但我似乎无法弄清楚为什么这段代码不起作用:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
// CONNECT TO MYSQL
$con = mysqli_connect("127.0.0.1","root","MySQLrootpass","cards");
if (mysqli_connect_errno()){
echo "<div style='text-align: center;'>";
echo "<h1>Could not connect to server, please try again later.</h1>";
echo "Failed to connect to MySQL: " . mysqli_connect_error();
echo "</div>";
}
$data = mysqli_query($con,"SELECT * FROM cards");
while($row = mysqli_fetch_array($data)){ ?>
<div id="card<?php echo $row["id"]; ?>" class="cardPost" style="background-image: url('Sprites/card.png');" onClick="sideData('card','<?php echo $row["id"]; ?>')">
<span class="cardTitle"><?php echo $row["name"]; ?></span>
<div class="elements">
<img class="elmPic" src="Sprites/elms/<?php echo $row["element"]; ?>Elm.png">
</div>
</div>
<?php}
// DISCONNECT FORM MYSQL
mysqli_close($con);
?>
我对整个 PHP 显示错误的事情很陌生,所以我不知道为什么不显示。
通过语法检查器运行后,它说 }
while 循环结束时是意外的,我不明白为什么,因为这段代码工作正常,直到我将 id 和 onClick 属性添加到 <div>
.
现在,当我删除它们时,它仍然不起作用。
另外,我知道这是这个 while 循环,因为当我评论它时,一切都运行良好。
我的页面上还有另一个,就像这个一样(带有 id 和 onClick),效果很好。
还有一件事,当我在第二个 while 循环中删除分号(从隐藏开始)时,一切仍然运行良好。
我知道这是一个非常具体的情况,但我们将非常感谢任何帮助。
最佳答案
I'm new to the whole php display error thing, so I don't know why there not displaying
ini_set
和error_reporting
是函数:与任何其他函数一样,它们在脚本运行时执行。如果您的脚本存在解析错误,它首先将永远不会运行,因此您的函数将没有机会执行任何操作。
您可以在 php.ini 文件中更改这些设置,这将允许它们在脚本执行之前生效(然后您将能够看到错误消息)。
display_errors = on
error_reporting = E_ALL
After running it through a syntax checker, it said that the } at the end of the while loop was unexpected, I don't understand why
<?php
之间应该有空格和}
.
关于php - 如何修复特定的 PHP 白屏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21947044/