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

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条)

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名