douxing9813 2015-09-16 09:20
浏览 96
已采纳

包含php-mysql连接文件时显示空白页面

I am using Ubuntu 14.04 and I am using lamp. I had a more complex issue but I figured out what is causing the error and made a small php-mysql connection snippet. When the connection file is included into the php/html file the whole thing displays a blank page.

My connect.php code:

  <?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();
}

?>

and my web page with connection file included:

    <?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);
?>
  • 写回答

1条回答 默认 最新

  • duanjiao7440 2015-09-16 09:24
    关注

    The following line in connect.php:

    if(mysqli_connect_errno(){
    

    Should be:

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

    You were not properly enclosing your condition with ().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘