doutaoer3148 2016-12-07 04:14
浏览 513
已采纳

mysqli_select_db()正好需要2个参数

Getting the errors:

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\Usersoot\Desktop\WebServer\htdocs\test.php on line 9

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\Usersoot\Desktop\WebServer\htdocs\test.php on line 13

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\Usersoot\Desktop\WebServer\htdocs\test.php on line 39

I can't notice the problem, kind of new to this, can anyone see the problem?

Any help is very appreciated!

<?php


//make connection
mysqli_connect('localhost', 'root', '');


//select db
mysqli_select_db('altislife-dev');

$sql="SELECT * FROM players";

$records=mysqli_query($sql);

?>

<html>

    <head>

        <title>Data</title>

    </head>

    <body>

        <table width="600" border="1" cellpadding="1" cellspacing="1">
        <tr>
        <th>uid</th>
        <th>name</th>
        <th>aliases</th>
        <th>playerid</th>
        <th>cash</th>
        <th>bankacc</th>
        <th>coplevel</th>
        <tr>

        <?php
        while($players=mysqli_fetch_assoc($records)) {

            echo "<tr>";
            echo "<td>".$players['uid']."</td>";
            echo "<td>".$players['name']."</td>";
            echo "<td>".$players['aliases']."</td>";
            echo "<td>".$players['playerid']."</td>";
            echo "<td>".$players['cash']."</td>";
            echo "<td>".$players['bankacc']."</td>";
            echo "<td>".$players['coplevel']."</td>";
            echo "</tr>";
        }

        ?>
        </table>
    </body>
</html>
  • 写回答

3条回答 默认 最新

  • douzhan1994 2016-12-07 04:18
    关注

    do the correction as below:

    $conn = mysqli_connect('localhost', 'root', '');
    

    the first thing that you have to pass connection variable in the select_db as first parameter. as below.

    mysqli_select_db($conn,'altislife-dev');
    

    also you have to pass connection variable in mysqli_query() as first parameter as given below.

    $records=mysqli_query($conn,$sql);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改