【问题标题】:Displaying blank page when including php-mysql connection file包含 php-mysql 连接文件时显示空白页
【发布时间】:2015-12-12 19:08:17
【问题描述】:

我正在使用 Ubuntu 14.04 并且我正在使用灯泡。我有一个更复杂的问题,但我找出了导致错误的原因并建立了一个小的 php-mysql 连接 sn-p。当连接文件包含在 php/html 文件中时,整个内容显示一个空白页面。

我的 connect.php 代码:

  <?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "ecalendar";
$conn = mysqli_connect($db_host,$db_user,$db_pass,$db_name);
if(mysqli_connect_errno(){
    echo "Error".mysqli_connect_errno();
}

?>

以及我的包含连接文件的网页:

    <?php
include "connect.php";
?>
<!DOCTYPE html>
<html>
<head>
    </head>
    <body>
        <p>Testing</p>
        <?php
            $sql="SELECT * FROM events WHERE eventid=1";
            $result = mysqli_query($sql);

        ?>
        <ul>
            <li><?php $row = mysqli_fetch_array($result);
                echo $result;

             ?>
            </li>
    </body>
</html>
<?php
mysqli_close($conn);
?>

【问题讨论】:

  • 检查您的 Apache 日志。
  • 你能打开错误报告吗?
  • Turn error reporting on 这样您就可以看到问题的描述。如果您在阅读错误后仍然无法解决问题,请在此处发布错误消息。

标签: php mysql ubuntu phpmyadmin lamp


【解决方案1】:

connect.php 中的以下行:

if(mysqli_connect_errno(){

应该是:

if(mysqli_connect_errno()){ // note the extra ')'

你没有用()正确地附上你的条件。

【讨论】:

  • 感谢 D4V1D 现在页面正在显示,但数据库记录仍然没有显示在页面中
  • 所以你的问题已经解决了。你应该问另一个,同时,接受能解决你问题的那个。另外,尝试echoing $row 而不是$result
  • 感谢 D4VID。 $row 没有用。我会搜索的。是的,我的问题已经解决了
  • @D4V1D 这一行出现问题&lt;?php $row = mysqli_fetch_array($result); echo $result; ?&gt; OP 尝试回显$result 而不是print_r($row);
猜你喜欢
  • 2012-03-27
  • 2011-04-28
  • 1970-01-01
  • 2011-08-11
  • 2019-03-28
  • 1970-01-01
  • 2013-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多