dozr13344 2018-07-02 05:43
浏览 704
已采纳

警告:mysqli_query()期望参数1为mysqli,null为何?

I am making a website for my high school annual project. The following error occurs in the php file :

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /host/home1/jbts/html/db/Plot-log.php on line 89

this is php source.

<?php
$link=mysqli_connect("localhost","xxxx","xxxxxxxxx","jbts");
if (!$link)
{ echo "MySQL error : "; echo mysqli_connect_error(); exit(); }
mysqli_set_charset($link,"utf8");
$sql = "select * from Plot-log";
$result = mysqli_query($link, $sql);
?>

and I used in html file like this.

<tr>
    <?  while($row=mysqli_query($con, $sql)){ ?>
        <tr> 
          <td> <?=$row[0]?></td> 
          <td> <?=$row[1]?></td>
          <td>  <?=$row[2]?></td>                                           
</tr>
    <?
    }
    ?>

i need your help... plz :)

  • 写回答

1条回答 默认 最新

  • doucong6884 2018-07-02 06:05
    关注

    To output the data you need to use one of the fetching methods - in this case mysqli_fetch_assoc

    <?php
        /* be consistent with the name of the db connection object - $link */
    
        $link=mysqli_connect("localhost","xxxx","xxxxxxxxx","jbts");
        if( !$link ) exit( "MySQL error : ". mysqli_connect_error() );
    
    
        mysqli_set_charset( $link, "utf8" );
        $sql = "select * from `Plot-log`";
    
        $result = mysqli_query( $link, $sql );
    
    ?>
    

    The names below need to be changed to the actual names of the columns in the table.

    <?php
        if( $result ){
            while( $rs=mysqli_fetch_assoc( $result ) ){
                echo "
                <tr>
                    <td>{$rs['FIELD_NAME_1']}</td>
                    <td>{$rs['FIELD_NAME_2']}</td>
                    <td>{$rs['FIELD_NAME_3']}</td>
                </tr>";
            }
        }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?